Clean up errors

This change eliminates all traces of the old, legacy errors and warnings.
It also renumbers everything so that we don't have any "gaps".  Finally,
it introduces a factory method for new errors and warnings, private to
this package, that ensures we don't accidentally register duplicate IDs.
This commit is contained in:
joeduffy 2017-01-25 17:58:16 -08:00
parent 8af53d5f69
commit 215afa6faf
7 changed files with 62 additions and 256 deletions

View file

@ -120,7 +120,7 @@ func (b *binder) resolveDep(dep pack.PackageURL) *symbols.ResolvedPackage {
}
// If we got to this spot, we could not find the dependency. Issue an error and bail out.
b.Diag().Errorf(errors.ErrorPackageNotFound, dep)
b.Diag().Errorf(errors.ErrorImportNotFound, dep)
return nil
}

View file

@ -2,152 +2,24 @@
package errors
import (
"github.com/marapongo/mu/pkg/diag"
"github.com/marapongo/mu/pkg/tokens"
// Binder errors are in the [500-600) range.
var (
ErrorMissingPackageName = newError(500, "This package is missing a `name` property (or it is empty)")
ErrorPackageURLMalformed = newError(501, "Package URL '%v' is malformed: %v")
ErrorImportNotFound = newError(502, "The imported package '%v' was not found; has it been installed?")
ErrorImportCycle = newError(
503, "An import cycle was found in %v's transitive closure of package imports")
ErrorTypeNotFound = newError(504, "Type '%v' could not be found: %v")
ErrorSymbolNotFound = newError(505, "Symbol '%v' could not be found: %v")
ErrorSymbolAlreadyExists = newError(506, "A symbol already exists with the name '%v'")
ErrorIncorrectExprType = newError(507, "Expression has an incorrect type; expected '%v', got '%v'")
ErrorMemberNotAccessible = newError(508, "Member '%v' is not accessible (it is %v)")
ErrorExpectedReturnExpr = newError(509, "Expected a return expression of type %v")
ErrorUnexpectedReturnExpr = newError(510, "Unexpected return expression; function has no return type (void)")
ErrorDuplicateLabel = newError(511, "Duplicate label '%v': %v")
ErrorUnknownJumpLabel = newError(512, "Unknown label '%v' used in the %v statement")
ErrorCannotNewAbstractClass = newError(513, "Cannot `new` an abstract class '%v'")
ErrorIllegalObjectLiteralType = newError(514,
"The type '%v' may not be used as an object literal type; only records and interfaces are permitted")
ErrorMissingRequiredProperty = newError(515, "Missing required property '%v'")
)
var ErrorMissingPackageName = &diag.Diag{
ID: 500,
Message: "This package is missing a `name` property (or it is empty)",
}
var ErrorIllegalStackVersion = &diag.Diag{
ID: 501,
Message: "This Stack's version '%v' is invalid: %v",
}
var ErrorSymbolAlreadyExists = &diag.Diag{
ID: 502,
Message: "A symbol already exists with the name '%v'",
}
var ErrorPackageNotFound = &diag.Diag{
ID: 503,
Message: "Package '%v' was not found; has it been installed?",
}
var ErrorTypeNotFound = &diag.Diag{
ID: 504,
Message: "Type '%v' could not be found: %v",
}
var ErrorSymbolNotFound = &diag.Diag{
ID: 504,
Message: "Symbol '%v' could not be found: %v",
}
var ErrorMemberNotAccessible = &diag.Diag{
ID: 505,
Message: "Member '%v' is not accessible (it is %v)",
}
var ErrorNonAbstractStacksMustDefineServices = &diag.Diag{
ID: 504,
Message: "Non-abstract stacks must declare at least one private or public service",
}
var ErrorCannotNewAbstractClass = &diag.Diag{
ID: 505,
Message: "Cannot `new` an abstract class '%v'",
}
var ErrorMissingRequiredProperty = &diag.Diag{
ID: 506,
Message: "Missing required property '%v'",
}
var ErrorUnrecognizedProperty = &diag.Diag{
ID: 507,
Message: "Unrecognized property '%v'",
}
var ErrorIncorrectExprType = &diag.Diag{
ID: 508,
Message: "Expression has an incorrect type; expected '%v', got '%v'",
}
var ErrorServiceNotFound = &diag.Diag{
ID: 509,
Message: "A service named '%v' was not found",
}
var ErrorServiceHasNoPublics = &diag.Diag{
ID: 510,
Message: "The service '%v' of type '%v' has no public entrypoint; it cannot be referenced",
}
var ErrorServiceHasManyPublics = &diag.Diag{
ID: 511,
Message: "The service '%v' of type '%v' has multiple public entrypoints; please choose one using a selector",
}
var ErrorServiceSelectorNotFound = &diag.Diag{
ID: 512,
Message: "No public by the given selector '%v' was found in service '%v' of type '%v'",
}
var ErrorServiceSelectorIsPrivate = &diag.Diag{
ID: 513,
Message: "The given selector '%v' references a private service in '%v' of type '%v'; it must be public",
}
var ErrorNotAName = &diag.Diag{
ID: 514,
Message: "The string '%v' is not a valid name (expected: " + tokens.NameRegexpPattern + ")",
}
var ErrorStackTypeExpected = &diag.Diag{
ID: 515,
Message: "A stack type was expected here; '%v' did not resolve to a stack ('%v')",
}
var ErrorSchemaTypeExpected = &diag.Diag{
ID: 516,
Message: "A schema type was expected here; '%v' did not resolve to a schema ('%v')",
}
var ErrorSchemaConstraintUnmet = &diag.Diag{
ID: 517,
Message: "Schema constraint %v unmet; expected %v, got %v",
}
var ErrorSchemaConstraintType = &diag.Diag{
ID: 518,
Message: "Unexpected type conflict with constraint %v; expected %v, got %v",
}
var ErrorImportCycle = &diag.Diag{
ID: 520,
Message: "An import cycle was found in %v's transitive closure of package imports",
}
var ErrorPackageURLMalformed = &diag.Diag{
ID: 521,
Message: "Package URL '%v' is malformed: %v",
}
var ErrorExpectedReturnExpr = &diag.Diag{
ID: 522,
Message: "Expected a return expression of type %v",
}
var ErrorUnexpectedReturnExpr = &diag.Diag{
ID: 523,
Message: "Unexpected return expression; function has no return type (void)",
}
var ErrorDuplicateLabel = &diag.Diag{
ID: 524,
Message: "Duplicate label '%v': %v",
}
var ErrorUnknownJumpLabel = &diag.Diag{
ID: 525,
Message: "Unknown label '%v' used in the %v statement",
}
var ErrorIllegalObjectLiteralType = &diag.Diag{
ID: 526,
Message: "The type '%v' may not be used as an object literal type; only records and interfaces are permitted",
}

View file

@ -2,56 +2,13 @@
package errors
import (
"github.com/marapongo/mu/pkg/diag"
// Compiler errors are in the [100-200) range.
var (
ErrorIO = newError(100, "An IO error occurred during the current operation: %v")
ErrorCouldNotReadMufile = newError(101, "An IO error occurred while reading the Mufile: %v")
ErrorIllegalMufileSyntax = newError(102, "A syntax error was detected while parsing the Mufile: %v")
ErrorIllegalWorkspaceSyntax = newError(103, "A syntax error was detected while parsing workspace settings: %v")
WarningIllegalMarkupFileCasing = newWarning(104, "A %v-like file was located, but it has incorrect casing")
WarningIllegalMarkupFileExt = newWarning(
105, "A %v-like file was located, but %v isn't a valid file extension (expected .json or .yaml)")
)
var ErrorMissingMufile = &diag.Diag{
ID: 100,
Message: "No Mufile was found in the given path or any of its parents (%v)",
}
var WarningIllegalMarkupFileCasing = &diag.Diag{
ID: 101,
Message: "A %v-like file was located, but it has incorrect casing",
}
var WarningIllegalMarkupFileExt = &diag.Diag{
ID: 102,
Message: "A %v-like file was located, but %v isn't a valid file extension (expected .json or .yaml)",
}
var ErrorIO = &diag.Diag{
ID: 103,
Message: "An IO error occurred during the current operation: %v",
}
var ErrorUnrecognizedCloudArch = &diag.Diag{
ID: 120,
Message: "The cloud architecture '%v' was not recognized",
}
var ErrorUnrecognizedSchedulerArch = &diag.Diag{
ID: 121,
Message: "The cloud scheduler architecture '%v' was not recognized",
}
var ErrorIllegalCloudSchedulerCombination = &diag.Diag{
ID: 122,
Message: "The cloud architecture '%v' is incompatible with scheduler '%v'",
}
var ErrorConflictingClusterArchSelection = &diag.Diag{
ID: 123,
Message: "The cloud architecture specification '%v' conflicts with cluster '%v's setting of '%v'",
}
var ErrorClusterNotFound = &diag.Diag{
ID: 124,
Message: "A cloud target '%v' was not found in the stack or cluster definition",
}
var ErrorMissingTarget = &diag.Diag{
ID: 125,
Message: "Neither a target nor cloud architecture was provided, and no defaults were found",
}

View file

@ -0,0 +1,3 @@
// Copyright 2016 Marapongo, Inc. All rights reserved.
package errors

View file

@ -2,11 +2,7 @@
package errors
import (
"github.com/marapongo/mu/pkg/diag"
// Eval errors are in the [1000,2000) range.
var (
ErrorUnhandledException = newError(1000, "An unhandled exception terminated the program: %v")
)
var ErrorUnhandledException = &diag.Diag{
ID: 1000,
Message: "An unhandled exception terminated the program: %v",
}

View file

@ -0,0 +1,26 @@
// Copyright 2016 Marapongo, Inc. All rights reserved.
package errors
import (
"github.com/marapongo/mu/pkg/diag"
"github.com/marapongo/mu/pkg/util/contract"
)
// errors tracks all existing errors, keyed by their unique ID.
var errors = make(map[diag.ID]*diag.Diag)
// newError registers a new error message underneath the given unique ID.
func newError(id diag.ID, message string) *diag.Diag {
contract.Assert(errors[id] == nil)
e := &diag.Diag{ID: id, Message: message}
errors[id] = e
return e
}
// newWarning registers a new warning message underneath the given unique ID.
func newWarning(id diag.ID, message string) *diag.Diag {
// At the moment, there isn't a distinction between errors and warnings; however, we use different functions just in
// case someday down the road there is, and so we don't have to go audit all callsites.
return newError(id, message)
}

View file

@ -1,48 +0,0 @@
// Copyright 2016 Marapongo, Inc. All rights reserved.
package errors
import (
"fmt"
"github.com/marapongo/mu/pkg/diag"
"github.com/marapongo/mu/pkg/tokens"
)
var ErrorCouldNotReadMufile = &diag.Diag{
ID: 150,
Message: "An IO error occurred while reading the Mufile: %v",
}
var ErrorIllegalMufileSyntax = &diag.Diag{
ID: 151,
Message: "A syntax error was detected while parsing the Mufile: %v",
}
var ErrorIllegalWorkspaceSyntax = &diag.Diag{
ID: 152,
Message: "A syntax error was detected while parsing workspace settings: %v",
}
var ErrorBadTemplate = &diag.Diag{
ID: 153,
Message: "A template error occurred: %v",
}
var ErrorIllegalMapLikeSyntax = &diag.Diag{
ID: 154,
Message: "The map type '%v' is malformed (expected syntax is '" +
fmt.Sprintf(string(tokens.MapTypeDecors), "K", "V") + "')",
}
var ErrorIllegalArrayLikeSyntax = &diag.Diag{
ID: 155,
Message: "The array type '%v' is malformed (expected syntax is '" +
fmt.Sprintf(string(tokens.ArrayTypeDecors), "T") + "')",
}
var ErrorIllegalNameLikeSyntax = &diag.Diag{
ID: 156,
Message: "The named type '%v' is malformed; " +
"expected format is '[[proto://]base.url/]stack/../name[@version]': %v",
}