2018-05-22 19:43:36 +00:00
|
|
|
// Copyright 2016-2018, Pulumi Corporation.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2016-11-19 18:17:44 +00:00
|
|
|
|
2017-01-15 22:26:48 +00:00
|
|
|
package contract
|
2016-11-19 18:17:44 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2016-11-20 00:13:13 +00:00
|
|
|
const assertMsg = "An assertion has failed"
|
2016-11-19 18:17:44 +00:00
|
|
|
|
2016-11-20 00:13:13 +00:00
|
|
|
// Assert checks a condition and Fails if it is false.
|
2023-02-08 19:00:57 +00:00
|
|
|
//
|
|
|
|
// Deprecated: Use Assertf.
|
2016-11-19 18:17:44 +00:00
|
|
|
func Assert(cond bool) {
|
|
|
|
if !cond {
|
2016-12-01 19:43:41 +00:00
|
|
|
failfast(assertMsg)
|
2016-11-19 18:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Begin merging MuPackage/MuIL into the compiler
This is the first change of many to merge the MuPack/MuIL formats
into the heart of the "compiler".
In fact, the entire meaning of the compiler has changed, from
something that took metadata and produced CloudFormation, into
something that takes MuPack/MuIL as input, and produces a MuGL
graph as output. Although this process is distinctly different,
there are several aspects we can reuse, like workspace management,
dependency resolution, and some amount of name binding and symbol
resolution, just as a few examples.
An overview of the compilation process is available as a comment
inside of the compiler.Compile function, although it is currently
unimplemented.
The relationship between Workspace and Compiler has been semi-
inverted, such that all Compiler instances require a Workspace
object. This is more natural anyway and moves some of the detection
logic "outside" of the Compiler. Similarly, Options has moved to
a top-level package, so that Workspace and Compiler may share
access to it without causing package import cycles.
Finally, all that templating crap is gone. This alone is cause
for mass celebration!
2017-01-18 01:04:15 +00:00
|
|
|
// Assertf checks a condition and Failfs if it is false, formatting and logging the given message.
|
|
|
|
func Assertf(cond bool, msg string, args ...interface{}) {
|
2016-11-19 18:17:44 +00:00
|
|
|
if !cond {
|
2016-12-01 19:43:41 +00:00
|
|
|
failfast(fmt.Sprintf("%v: %v", assertMsg, fmt.Sprintf(msg, args...)))
|
2016-11-19 18:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-25 17:46:05 +00:00
|
|
|
|
|
|
|
// AssertNoError will Fail if the error is non-nil.
|
2023-02-08 19:00:57 +00:00
|
|
|
//
|
|
|
|
// Deprecated: Use AssertNoErrorf.
|
2017-10-25 17:46:05 +00:00
|
|
|
func AssertNoError(err error) {
|
|
|
|
if err != nil {
|
|
|
|
failfast(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AssertNoErrorf will Fail if the error is non-nil, adding the additional log message.
|
|
|
|
func AssertNoErrorf(err error, msg string, args ...interface{}) {
|
|
|
|
if err != nil {
|
|
|
|
failfast(fmt.Sprintf("error %v: %v. source error: %v", assertMsg, fmt.Sprintf(msg, args...), err))
|
|
|
|
}
|
|
|
|
}
|