syntax = "proto3";

// These error details are supplied in google.rpc.Status#details as described in "Google APIs, Error Model" (https://cloud.google.com/apis/design/errors#error_model)
// and extend standard Error Details defined in https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto

package temporal.api.errordetails.v1;

option go_package = "go.temporal.io/api/errordetails/v1;errordetails";
option java_package = "io.temporal.api.errordetails.v1";
option java_multiple_files = true;
option java_outer_classname = "MessageProto";
option ruby_package = "Temporalio::Api::ErrorDetails::V1";
option csharp_namespace = "Temporalio.Api.ErrorDetails.V1";

import "google/protobuf/any.proto";
import "temporal/api/common/v1/message.proto";

import "temporal/api/enums/v1/failed_cause.proto";
import "temporal/api/enums/v1/namespace.proto";
import "temporal/api/failure/v1/message.proto";

message NotFoundFailure {
    string current_cluster = 1;
    string active_cluster = 2;
}

message WorkflowExecutionAlreadyStartedFailure {
    string start_request_id = 1;
    string run_id = 2;
}

message NamespaceNotActiveFailure {
    string namespace = 1;
    string current_cluster = 2;
    string active_cluster = 3;
}

// NamespaceUnavailableFailure is returned by the service when a request addresses a namespace that is unavailable. For
// example, when a namespace is in the process of failing over between clusters.
// This is a transient error that should be automatically retried by clients.
message NamespaceUnavailableFailure {
    string namespace = 1;
}

message NamespaceInvalidStateFailure {
    string namespace = 1;
    // Current state of the requested namespace.
    temporal.api.enums.v1.NamespaceState state = 2;
    // Allowed namespace states for requested operation.
    // For example NAMESPACE_STATE_DELETED is forbidden for most operations but allowed for DescribeNamespace.
    repeated temporal.api.enums.v1.NamespaceState allowed_states = 3;
}

message NamespaceNotFoundFailure {
    string namespace = 1;
}

message NamespaceAlreadyExistsFailure {
}

message ClientVersionNotSupportedFailure {
    string client_version = 1;
    string client_name = 2;
    string supported_versions = 3;
}

message ServerVersionNotSupportedFailure {
    string server_version = 1;
    string client_supported_server_versions = 2;
}

message CancellationAlreadyRequestedFailure {
}

message QueryFailedFailure {
    // The full reason for this query failure. May not be available if the response is generated by an old
    // SDK. This field can be encoded by the SDK's failure converter to support E2E encryption of messages and stack
    // traces.
    temporal.api.failure.v1.Failure failure = 1;
}

message PermissionDeniedFailure {
    string reason = 1;
}

message ResourceExhaustedFailure {
    temporal.api.enums.v1.ResourceExhaustedCause cause = 1;
    temporal.api.enums.v1.ResourceExhaustedScope scope = 2;
}

message SystemWorkflowFailure {
    // WorkflowId and RunId of the Temporal system workflow performing the underlying operation.
    // Looking up the info of the system workflow run may help identify the issue causing the failure.
    temporal.api.common.v1.WorkflowExecution workflow_execution = 1;
    // Serialized error returned by the system workflow performing the underlying operation.
    string workflow_error = 2;
}

message WorkflowNotReadyFailure {
}

message NewerBuildExistsFailure {
    // The current default compatible build ID which will receive tasks
    string default_build_id = 1;
}

message MultiOperationExecutionFailure {
    // One status for each requested operation from the failed MultiOperation. The failed
    // operation(s) have the same error details as if it was executed separately. All other operations have the
    // status code `Aborted` and `MultiOperationExecutionAborted` is added to the details field.
    repeated OperationStatus statuses = 1;

    // NOTE: `OperationStatus` is modelled after
    // [`google.rpc.Status`](https://github.com/googleapis/googleapis/blob/master/google/rpc/status.proto).
    //
    // (-- api-linter: core::0146::any=disabled
    //     aip.dev/not-precedent: details are meant to hold arbitrary payloads. --)
    message OperationStatus {
        int32 code = 1;
        string message = 2;
        repeated google.protobuf.Any details = 3;
    }
}

// An error indicating that an activity execution failed to start. Returned when there is an existing activity with the
// given activity ID, and the given ID reuse and conflict policies do not permit starting a new one or attaching to an
// existing one.
message ActivityExecutionAlreadyStartedFailure {
    string start_request_id = 1;
    string run_id = 2;
}

// An error indicating that a Nexus operation failed to start. Returned when there is an existing operation with the
// given operation ID, and the given ID reuse and conflict policies do not permit starting a new one or attaching to an
// existing one.
message NexusOperationExecutionAlreadyStartedFailure {
    string start_request_id = 1;
    string run_id = 2;
}
