exaerror

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: MIT Imports: 3 Imported by: 1

README

Go Error Reporting

This project contains a Go-Builder for Exasol error messages.

Build Status Go Reference Build

Quality Gate Status Coverage Security Rating Vulnerabilities

Usage

Including Go Error Reporting

Add this to your go.mod:

require (
    github.com/exasol/error-reporting-go v0.1.1
)

Then import the library in your .go files:

import (
    "github.com/exasol/error-reporting-go"
)
Simple Messages
renderedString := exaerror.New("E-TEST-1").Message("Something went wrong.").String()

Result: E-TEST-1: Something went wrong.

Error Identifiers

The error identifier (E-TEST-1 in the previous example) uniquely identifies the error and consists of three parts:

  • Severity: E = Error, F = Failure, W = Warning
  • One or two tags separated with a dash - that identify the application or module, e.g. MYAPP or MYAPP-MOD1
  • An integer as index

Error Identifiers must be unique.

See the Error Code Model and the Error Code Crawler for details.

As native go error
err := exaerror.New("E-TEST-1").Message("Something went wrong.")
fmt.Println(err)  // fmt package can print errors automatically
fmt.Println(err.Error())  // Print error message explicit via Error() function

Result: E-TEST-1: Something went wrong.

Parameters

You can specify placeholders in the message and fill them up with parameters values:

renderedString := exaerror.New("E-TEST-2").Message("Unknown input {{input}}.").Parameter("input", "unknown").String()

or inline

renderedString := exaerror.New("E-TEST-2").Messagef("Unknown input {{input}}.", "unknown").String()

Result: E-TEST-2: Unknown input 'unknown'.

ParameterWithDescription(name, value, description) method also gets a parameter description which will be used to generate a parameter description for the error-catalog.

The builder automatically quotes parameters with single quotes. If you want to avoid quotes, use the |uq suffix in the correspondent placeholder:

renderedString := exaerror.New("E-TEST-2").Message("Unknown input {{input|uq}}.").Parameter("input", 2).String()

result: E-TEST-2: Unknown input 2.

Mitigations

The mitigations describe those actions the user can follow to overcome the error, and are specified as follows:

renderedString := exaerror.New("E-TEST-3").Message("Too little disk space.").Mitigation("Delete something.").String()

Result: E-TEST-3: Too little disk space. Delete something.

Additional Resources

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExaError

type ExaError struct {
	// contains filtered or unexported fields
}

func New

func New(errorCode string) *ExaError

func (*ExaError) Error

func (builder *ExaError) Error() string

func (*ExaError) Message

func (builder *ExaError) Message(message string) *ExaError

func (*ExaError) Messagef

func (builder *ExaError) Messagef(format string, a ...interface{}) *ExaError

func (*ExaError) Mitigation

func (builder *ExaError) Mitigation(mitigation string) *ExaError

func (*ExaError) Parameter

func (builder *ExaError) Parameter(name string, value interface{}) *ExaError

func (*ExaError) ParameterWithDescription

func (builder *ExaError) ParameterWithDescription(name string, value interface{}, description string) *ExaError

func (*ExaError) String

func (builder *ExaError) String() string

Jump to

Keyboard shortcuts

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