diagnostic

package
v0.46.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServerErrorMessage

func ServerErrorMessage(body string) string

ServerErrorMessage extracts the human-readable reason from a platform error body, falling back to a truncated excerpt of the raw body so the server's explanation is never silently dropped.

Platform errors arrive in two shapes — {"error":{"message":…,"details":{…}}} and a bare {"message":…} — and "details" of the first is where a 403 that really is a scope problem names the scopes it wanted. Dropping it would send the caller after the IAM policy gate when the token was at fault, so it is appended to the message.

func SuggestionsForStatusCode

func SuggestionsForStatusCode(statusCode int) []string

SuggestionsForStatusCode returns troubleshooting suggestions for an HTTP status code. Exported so the agent envelope can carry the same advice for a bare SDK HTTP failure that a diagnostic.Error carries for a wrapped one.

func URLSuggestions

func URLSuggestions(environmentURL string) []string

URLSuggestions returns troubleshooting suggestions based on URL problems. This adds the dtctl-specific "Update with: dtctl ctx set" hint.

Types

type Error

type Error struct {
	Operation   string   // e.g., "get workflows", "apply dashboard"
	StatusCode  int      // HTTP status code
	Message     string   // Error message from API
	RequestID   string   // Request ID for support escalation
	Suggestions []string // Actionable troubleshooting suggestions
	Err         error    // Underlying error
}

Error represents an enhanced diagnostic error with contextual help

func SettingsForbidden

func SettingsForbidden(d SettingsDenial) *Error

SettingsForbidden builds the 403 error for a Settings 2.0 object operation.

It is the Settings-API counterpart of the Grail-file 403 handling added for github.com/Dynatrace/dtctl#344, and exists for the same reason: the OAuth scope in the token and the IAM permission of the same name are two independent gates, so "access denied" without the server's explanation reads like a token problem even when the token is fine. Per the settings service definition, settings:objects:read and settings:objects:write are IAM permissions conditioned on settings:schemaId, settings:schemaGroup and settings:scope among others — which is why access to one schema says nothing about access to another.

This lives in diagnostic rather than next to a handler because four resource packages (aws/azure/gcp connections, anomaly detectors) share the Settings API and would otherwise each carry a copy. The Grail-file equivalent stays in pkg/resources/lookup, which is its only caller.

func (*Error) AddSuggestion

func (e *Error) AddSuggestion(suggestion string) *Error

AddSuggestion adds a custom suggestion to the error

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface

func (*Error) ExitCode

func (e *Error) ExitCode() int

ExitCode returns the appropriate exit code for this error

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the underlying error for errors.Is/As compatibility

func (*Error) WithRequestID

func (e *Error) WithRequestID(requestID string) *Error

WithRequestID adds a request ID to the error

func (*Error) WithStatusCode

func (e *Error) WithStatusCode(statusCode int) *Error

WithStatusCode sets the status code (useful when wrapping non-API errors)

type SettingsDenial

type SettingsDenial struct {
	// Operation is the user-facing action, rendered as "Failed to <Operation>",
	// e.g. `create gcp_connection` or `update anomaly detector "vu9U…"`.
	Operation string
	// Permission is the OAuth scope and IAM permission name the operation needs,
	// i.e. settings:objects:read or settings:objects:write.
	Permission string
	// SchemaID is the settings schema the object belongs to. It is the condition
	// an IAM policy statement is usually written against, so it goes into the
	// suggested statement verbatim. May be empty when the operation targets an
	// existing object whose schema is not known at the call site.
	SchemaID string
	// Body is the raw response body. Never discard it — the server's reason for
	// the denial is in here, and hiding it is what turned issue #344 into a
	// support case.
	Body string
	// ExistingObject is true for operations on an object that already exists
	// (get, update, delete). Settings objects carry an owner, so those can be
	// denied for a reason no policy on the schema fixes.
	ExistingObject bool
}

SettingsDenial describes a 403 from the Settings 2.0 objects API (/platform/classic/environment-api/v2/settings/objects).

type URLProblem

type URLProblem = urls.Problem

URLProblem describes a detected issue with an environment URL. Alias for urls.Problem from the SDK.

func CheckEnvironmentURL

func CheckEnvironmentURL(environmentURL string) []URLProblem

CheckEnvironmentURL inspects an environment URL for common mistakes. Delegates to urls.Check from the SDK.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL