@@ -217,6 +217,7 @@ func (b *Bundle) populateExports(updateOptions bool, bi *BundleInstance) error {
217
217
dec .DisallowUnknownFields ()
218
218
if err = dec .Decode (& b .Options ); err != nil {
219
219
if uerr := json .Unmarshal (data , & b .Options ); uerr != nil {
220
+ uerr = beautifyJSONUnmarshalError (data , uerr )
220
221
err = errext .WithAbortReasonIfNone (
221
222
errext .WithExitCodeIfNone (uerr , exitcodes .InvalidConfig ),
222
223
errext .AbortedByScriptError ,
@@ -247,6 +248,19 @@ func (b *Bundle) populateExports(updateOptions bool, bi *BundleInstance) error {
247
248
return nil
248
249
}
249
250
251
+ func beautifyJSONUnmarshalError (data []byte , err error ) error {
252
+ unmarshalTypError := new (json.UnmarshalTypeError )
253
+ if errors .As (err , & unmarshalTypError ) {
254
+ e := unmarshalTypError
255
+ previousNewLineIndex := max (bytes .LastIndexByte (data [:e .Offset ], '\n' ), 0 )
256
+ nextNewLineIndex := max (bytes .IndexByte (data [e .Offset :], '\n' ), len (data )- 1 )
257
+
258
+ info := strings .TrimSpace (string (data [previousNewLineIndex :nextNewLineIndex ]))
259
+ err = fmt .Errorf ("parsing options from script got error while parsing %q: %w" , info , e )
260
+ }
261
+ return err
262
+ }
263
+
250
264
// Instantiate creates a new runtime from this bundle.
251
265
func (b * Bundle ) Instantiate (ctx context.Context , vuID uint64 ) (* BundleInstance , error ) {
252
266
// Instantiate the bundle into a new VM using a bound init context. This uses a context with a
0 commit comments