Replace panic with ModuleErrorf
This is a followup cleanup for aosp/2876754 and replaces panic with ctx.ModuleErrorf. The latter creates a more expressive build error. Implementation details - export moduleErrorf interface from build/soong/android. This minimal interface will be used as a parameter for `DexJarBuildPath` - Add ModuleErrorf to the function signature of DexJarBuildPath. This parameter only gets used for Import and SdkLibraryImport structs. These two can have duplicate deapexer definitions, and ModuleErrorf will be used to report that error - Create a minimal implementation of `ModuleErrorf` in tests of java and apex Test: m nothing --no-skip-soong-tests Change-Id: I0febec651f40c3f04deb957e64133c94b80fbd78
This commit is contained in:
@@ -181,13 +181,13 @@ type errorfContext interface {
|
||||
|
||||
var _ errorfContext = blueprint.SingletonContext(nil)
|
||||
|
||||
// moduleErrorf is the interface containing the ModuleErrorf method matching
|
||||
// ModuleErrorfContext is the interface containing the ModuleErrorf method matching
|
||||
// the ModuleErrorf method in blueprint.ModuleContext.
|
||||
type moduleErrorf interface {
|
||||
type ModuleErrorfContext interface {
|
||||
ModuleErrorf(format string, args ...interface{})
|
||||
}
|
||||
|
||||
var _ moduleErrorf = blueprint.ModuleContext(nil)
|
||||
var _ ModuleErrorfContext = blueprint.ModuleContext(nil)
|
||||
|
||||
// reportPathError will register an error with the attached context. It
|
||||
// attempts ctx.ModuleErrorf for a better error message first, then falls
|
||||
@@ -200,7 +200,7 @@ func reportPathError(ctx PathContext, err error) {
|
||||
// attempts ctx.ModuleErrorf for a better error message first, then falls
|
||||
// back to ctx.Errorf.
|
||||
func ReportPathErrorf(ctx PathContext, format string, args ...interface{}) {
|
||||
if mctx, ok := ctx.(moduleErrorf); ok {
|
||||
if mctx, ok := ctx.(ModuleErrorfContext); ok {
|
||||
mctx.ModuleErrorf(format, args...)
|
||||
} else if ectx, ok := ctx.(errorfContext); ok {
|
||||
ectx.Errorf(format, args...)
|
||||
|
Reference in New Issue
Block a user