chromium/chromeos/crosapi/mojom/telemetry_extension_exception.mojom

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Definitions for the exception API exposed by the Telemetry Extension's
// crosapi interface (consisting of ProbeService, DiagnosticsService and
// EventService).

// NOTE: This mojom is based on the cros_healthd exception type defined in:
// chromeos/ash/services/cros_healthd/public/mojom/cros_healthd_exception.mojom
// All major changes should be adopted.

module crosapi.mojom;

// A generic exception type for Telemetry Extension's crosapi interface.
//
// When we raise Exception through a mojo disconnection, we will encode it to a
// mojo disconnection error. A mojo disconnection error contains an uint32 error
// code and a string message. The error code is set to |reason| and the message
// is set to |debug_message|.
//
// NextMinVersion: 1, NextIndex: 2
[Stable]
struct TelemetryExtensionException {
  // A specific reason for clients to handle exceptions (e.g. showing a
  // specific message to UI). Use this instead of parsing |debug_message|.
  // Only add a new reason if there is a client handling that reason. Don’t add
  // reasons like kServiceUnavailable, but something like
  // kFailedToCallFooService, to make it specific.
  // When we raise Exception through a mojo disconnection, this will be the
  // mojo error code.
  [Stable, Extensible]
  enum Reason {
    // This is required for backwards compatibility. Don't raise this.
    // Set to 1 because 0 is reserved for kMojoDisconnectWithoutReason.
    [Default] kUnmappedEnumField = 1,
    // This is for compatibility with a mojo built-in disconnection error.
    // Don't raise this. Its value must be "0".
    kMojoDisconnectWithoutReason = 0,
    // Any other exceptions that we don't expect to happen. Clients should
    // simply report the error. If there is no client to handle this exception,
    // use this as the reason.
    kUnexpected = 2,
    // Raises this if clients try to run an unsupported feature. Note that
    // clients should use methods which return `TelemetryExtensionSupportStatus`
    // for support status check.
    kUnsupported = 3,
    // Raises this if a camera frontend needs to be opened but it is actually
    // not opened.
    [MinVersion=1] kCameraFrontendNotOpened = 4,
  };

  Reason reason@0;
  // A human readable message for debugging. If a client want to handle a
  // specific exception, use |reason|. Don't rely on the content because it
  // could change anytime.
  string debug_message@1;
};

// The result type of support status check of the Telemetry Event API.
//
// NextMinVersion: 1
[Stable, Extensible]
union TelemetryExtensionSupportStatus {
  // This is required for backwards compatibility. Don't use this.
  [Default] int8 unmapped_union_field;
  // This is set if any exception happens before we can determine whether the
  // feature is supported.
  TelemetryExtensionException exception;
  // The feature is supported.
  TelemetryExtensionSupported supported;
  // The feature is not supported.
  TelemetryExtensionUnsupported unsupported;
};

// Empty struct for future extensibility.
//
// NextMinVersion: 1, NextIndex: 0
[Stable]
struct TelemetryExtensionSupported {};

// Details about the unsupported reason.
//
// NextMinVersion: 1, NextIndex: 2
[Stable]
struct TelemetryExtensionUnsupported {
  // A human readable message for debugging. If a client want to handle a
  // specific exception, use |reason|. Don't rely on the content because it
  // could change anytime.
  string debug_message@0;
  // A union for the detailed reason.
  TelemetryExtensionUnsupportedReason? reason@1;
};

// Empty union for future extensibility. This can be used to pass the details
// about which config is missing or which policy is disabled. E.g. Add a field
// `PolicyEnum disabled_by_this_policy;`.
//
// NextMinVersion: 1
[Stable, Extensible]
union TelemetryExtensionUnsupportedReason {
  // This is required for backwards compatibility. Don't use this.
  [Default] int8 unmapped_union_field;
};