errors

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package errors provides enhanced error handling for the build system.

Index

Constants

View Source
const (
	CategoryDetection = "detection"
	CategoryTemplate  = "template"
	CategoryBuild     = "build"
	CategoryTimeout   = "timeout"
	CategoryResource  = "resource"
	CategoryConfig    = "config"
)

Error categories for build failures.

View Source
const (
	CodeNoLanguageDetected   = "NO_LANGUAGE_DETECTED"
	CodeMultipleLanguages    = "MULTIPLE_LANGUAGES"
	CodeUnsupportedLanguage  = "UNSUPPORTED_LANGUAGE"
	CodeRepositoryAccess     = "REPOSITORY_ACCESS_FAILED"
	CodeTemplateNotFound     = "TEMPLATE_NOT_FOUND"
	CodeTemplateRenderFailed = "TEMPLATE_RENDER_FAILED"
	CodeInvalidFlakeSyntax   = "INVALID_FLAKE_SYNTAX"
	CodeBuildFailed          = "BUILD_FAILED"
	CodeBuildTimeout         = "BUILD_TIMEOUT"
	CodeBuildOOM             = "BUILD_OOM"
	CodeVendorHashFailed     = "VENDOR_HASH_FAILED"
	CodeDockerfileNotFound   = "DOCKERFILE_NOT_FOUND"
	CodeFlakeNotFound        = "FLAKE_NOT_FOUND"
	CodeDependencyMissing    = "DEPENDENCY_MISSING"
	CodeInvalidConfig        = "INVALID_CONFIG"
	CodeNixpacksFailed       = "NIXPACKS_FAILED"
)

Error codes for specific failure types.

Variables

This section is empty.

Functions

func IsBuildError

func IsBuildError(err error) bool

IsBuildError checks if an error is a BuildError.

Types

type BuildError

type BuildError struct {
	Err            error
	Code           string
	Category       string
	Strategy       models.BuildStrategy
	GeneratedFlake string
	Suggestions    []string
	DetectedIssues []string
	NextSteps      []string
	CanRetryAsOCI  bool
}

BuildError is an error type that can be converted to a BuildErrorResponse.

func AsBuildError

func AsBuildError(err error) (*BuildError, bool)

AsBuildError attempts to convert an error to a BuildError.

func ErrorFromCode

func ErrorFromCode(code string, err error) *BuildError

ErrorFromCode creates a BuildError from an error code.

func NewBuildError

func NewBuildError(err error, code, category string) *BuildError

NewBuildError creates a new BuildError with the given parameters.

func NewBuildFailedError

func NewBuildFailedError(err error) *BuildError

NewBuildFailedError creates a new build error.

func NewBuildOOMError

func NewBuildOOMError() *BuildError

NewBuildOOMError creates an error for out-of-memory failures.

func NewBuildTimeoutError

func NewBuildTimeoutError(timeout string) *BuildError

NewBuildTimeoutError creates an error for build timeouts.

func NewDependencyMissingError

func NewDependencyMissingError(dependencies []string) *BuildError

NewDependencyMissingError creates an error for missing dependencies.

func NewDetectionError

func NewDetectionError(err error, code string) *BuildError

NewDetectionError creates a new detection error.

func NewDockerfileNotFoundError

func NewDockerfileNotFoundError() *BuildError

NewDockerfileNotFoundError creates an error for missing Dockerfile.

func NewFlakeNotFoundError

func NewFlakeNotFoundError() *BuildError

NewFlakeNotFoundError creates an error for missing flake.nix.

func NewInvalidConfigError

func NewInvalidConfigError(field, message string) *BuildError

NewInvalidConfigError creates an error for invalid configuration.

func NewInvalidFlakeSyntaxError

func NewInvalidFlakeSyntaxError(err error, flakeContent string) *BuildError

NewInvalidFlakeSyntaxError creates an error for invalid flake syntax.

func NewMultipleLanguagesError

func NewMultipleLanguagesError(languages []string) *BuildError

NewMultipleLanguagesError creates an error for when multiple languages are detected.

func NewNixpacksError

func NewNixpacksError(err error) *BuildError

NewNixpacksError creates an error for Nixpacks failures.

func NewNoLanguageDetectedError

func NewNoLanguageDetectedError() *BuildError

NewNoLanguageDetectedError creates an error for when no language can be detected.

func NewRepositoryAccessError

func NewRepositoryAccessError(err error) *BuildError

NewRepositoryAccessError creates an error for repository access failures.

func NewTemplateError

func NewTemplateError(err error, code string) *BuildError

NewTemplateError creates a new template error.

func NewTemplateNotFoundError

func NewTemplateNotFoundError(templateName string) *BuildError

NewTemplateNotFoundError creates an error for missing templates.

func NewTemplateRenderError

func NewTemplateRenderError(err error, templateName string) *BuildError

NewTemplateRenderError creates an error for template rendering failures.

func NewUnsupportedLanguageError

func NewUnsupportedLanguageError(language string) *BuildError

NewUnsupportedLanguageError creates an error for unsupported languages.

func NewVendorHashError

func NewVendorHashError(err error) *BuildError

NewVendorHashError creates an error for vendor hash calculation failures.

func (*BuildError) Error

func (e *BuildError) Error() string

Error implements the error interface.

func (*BuildError) ToResponse

func (e *BuildError) ToResponse() *BuildErrorResponse

ToResponse converts the BuildError to a BuildErrorResponse.

func (*BuildError) Unwrap

func (e *BuildError) Unwrap() error

Unwrap returns the underlying error.

func (*BuildError) WithCanRetryAsOCI

func (e *BuildError) WithCanRetryAsOCI(canRetry bool) *BuildError

WithCanRetryAsOCI sets whether the build can be retried as OCI.

func (*BuildError) WithDetectedIssues

func (e *BuildError) WithDetectedIssues(issues ...string) *BuildError

WithDetectedIssues sets the detected issues on the error.

func (*BuildError) WithGeneratedFlake

func (e *BuildError) WithGeneratedFlake(flake string) *BuildError

WithGeneratedFlake sets the generated flake content on the error.

func (*BuildError) WithNextSteps

func (e *BuildError) WithNextSteps(steps ...string) *BuildError

WithNextSteps sets the next steps on the error.

func (*BuildError) WithStrategy

func (e *BuildError) WithStrategy(strategy models.BuildStrategy) *BuildError

WithStrategy sets the build strategy on the error.

func (*BuildError) WithSuggestions

func (e *BuildError) WithSuggestions(suggestions ...string) *BuildError

WithSuggestions sets the suggestions on the error.

type BuildErrorResponse

type BuildErrorResponse struct {
	// Error is the main error message.
	Error string `json:"error"`

	// Code is a machine-readable error code.
	Code string `json:"code"`

	// Category groups errors by type (detection, template, build, timeout).
	Category string `json:"category"`

	// Strategy is the build strategy that was being used when the error occurred.
	Strategy string `json:"strategy,omitempty"`

	// GeneratedFlake contains the generated flake.nix content for debugging template issues.
	GeneratedFlake string `json:"generated_flake,omitempty"`

	// Suggestions provides actionable suggestions to resolve the error.
	Suggestions []string `json:"suggestions,omitempty"`

	// Documentation is a URL to relevant documentation.
	Documentation string `json:"documentation_url,omitempty"`

	// CanRetryAsOCI indicates whether the build can be retried as an OCI build.
	CanRetryAsOCI bool `json:"can_retry_as_oci"`

	// DetectedIssues lists specific problems found during the build.
	DetectedIssues []string `json:"detected_issues,omitempty"`

	// NextSteps provides guidance on what the user should do next.
	NextSteps []string `json:"next_steps,omitempty"`
}

BuildErrorResponse provides detailed error information with suggestions and next steps.

func ToErrorResponse

func ToErrorResponse(err error) *BuildErrorResponse

ToErrorResponse converts any error to a BuildErrorResponse. If the error is already a BuildError, it uses its response. Otherwise, it creates a generic error response.

Jump to

Keyboard shortcuts

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