Skip to content

Return user-facing error from Test.readFile on file-not-found - #4469

Merged
SupunS merged 1 commit into
masterfrom
holyfuchs/fix-readfile-error
Apr 16, 2026
Merged

SupunS merged 1 commit into
masterfrom
holyfuchs/fix-readfile-error

Conversation

@holyfuchs

Copy link
Copy Markdown
Contributor

Closes #4468

Summary

  • Test.readFile previously panicked with the raw OS error, which the interpreter wrapped in internal error: unexpected, producing a confusing full goroutine stack trace instead of a useful message
  • Wrapped the error in errors.NewDefaultUserError so callers see a clean, actionable message: cannot read file "does/not/exist.cdc": open does/not/exist.cdc: no such file or directory
  • Added TestReadFile covering both the success path and the file-not-found error case

@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions

Copy link
Copy Markdown

Benchstat comparison

  • Base branch: onflow:master
  • Base commit: c35ce67
Results

old.txtnew.txt
time/opdelta
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ByteArrayTransfer-41.29µs ± 0%1.25µs ± 0%~(p=1.000 n=1+1)
ByteArrayValueToByteSlice-482.9ns ± 0%78.4ns ± 0%~(p=1.000 n=1+1)
ByteSliceToByteArrayValue-41.12µs ± 0%1.08µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ContractFunctionInvocation-4413µs ± 0%416µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
EMVAddressTransfer-43.50µs ± 0%3.57µs ± 0%~(p=1.000 n=1+1)
Emit-44.80ms ± 0%4.79ms ± 0%~(p=1.000 n=1+1)
EnumTransfer-41.37µs ± 0%1.46µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ExportType/composite_type-4274ns ± 0%275ns ± 0%~(p=1.000 n=1+1)
ExportType/simple_type-477.8ns ± 0%77.7ns ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ImperativeFib-424.3µs ± 0%23.6µs ± 0%~(p=1.000 n=1+1)
InterpretRecursionFib-42.35ms ± 0%2.38ms ± 0%~(p=1.000 n=1+1)
NewInterpreter/new_interpreter-4900ns ± 0%904ns ± 0%~(p=1.000 n=1+1)
NewInterpreter/new_sub-interpreter-4338ns ± 0%344ns ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
RuntimeFungibleTokenTransferInterpreter-4660µs ± 0%646µs ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransferVM-4717µs ± 0%726µs ± 0%~(p=1.000 n=1+1)
RuntimeResourceDictionaryValues-42.98ms ± 0%2.89ms ± 0%~(p=1.000 n=1+1)
RuntimeResourceTracking-410.4ms ± 0%10.4ms ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-415.6µs ± 0%15.7µs ± 0%~(p=1.000 n=1+1)
RuntimeVMInvokeContractImperativeFib-443.7µs ± 0%41.5µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ValueIsSubtypeOfSemaType-460.7ns ± 0%61.0ns ± 0%~(p=1.000 n=1+1)
 
alloc/opdelta
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ByteArrayTransfer-41.02kB ± 0%1.08kB ± 0%~(p=1.000 n=1+1)
ByteArrayValueToByteSlice-432.0B ± 0%32.0B ± 0%~(all equal)
ByteSliceToByteArrayValue-4874B ± 0%870B ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ContractFunctionInvocation-4144kB ± 0%144kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
EMVAddressTransfer-42.45kB ± 0%2.46kB ± 0%~(p=1.000 n=1+1)
Emit-41.51MB ± 0%1.51MB ± 0%~(p=1.000 n=1+1)
EnumTransfer-4833B ± 0%833B ± 0%~(all equal)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ExportType/composite_type-4120B ± 0%120B ± 0%~(all equal)
ExportType/simple_type-40.00B 0.00B ~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ImperativeFib-48.30kB ± 0%8.30kB ± 0%~(all equal)
InterpretRecursionFib-41.19MB ± 0%1.19MB ± 0%~(p=1.000 n=1+1)
NewInterpreter/new_interpreter-4976B ± 0%976B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-4232B ± 0%232B ± 0%~(all equal)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
RuntimeFungibleTokenTransferInterpreter-4164kB ± 0%165kB ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransferVM-4188kB ± 0%188kB ± 0%~(p=1.000 n=1+1)
RuntimeResourceDictionaryValues-41.77MB ± 0%1.76MB ± 0%~(p=1.000 n=1+1)
RuntimeResourceTracking-46.98MB ± 0%6.96MB ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-48.09kB ± 0%8.10kB ± 0%~(p=1.000 n=1+1)
RuntimeVMInvokeContractImperativeFib-413.4kB ± 0%13.4kB ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ValueIsSubtypeOfSemaType-432.0B ± 0%32.0B ± 0%~(all equal)
 
allocs/opdelta
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ByteArrayTransfer-47.00 ± 0%7.00 ± 0%~(all equal)
ByteArrayValueToByteSlice-41.00 ± 0%1.00 ± 0%~(all equal)
ByteSliceToByteArrayValue-45.00 ± 0%5.00 ± 0%~(all equal)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ContractFunctionInvocation-42.25k ± 0%2.25k ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
EMVAddressTransfer-429.0 ± 0%29.0 ± 0%~(all equal)
Emit-440.0k ± 0%40.0k ± 0%~(p=1.000 n=1+1)
EnumTransfer-413.0 ± 0%13.0 ± 0%~(all equal)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ExportType/composite_type-43.00 ± 0%3.00 ± 0%~(all equal)
ExportType/simple_type-40.00 0.00 ~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ImperativeFib-4176 ± 0%176 ± 0%~(all equal)
InterpretRecursionFib-417.7k ± 0%17.7k ± 0%~(all equal)
NewInterpreter/new_interpreter-415.0 ± 0%15.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-44.00 ± 0%4.00 ± 0%~(all equal)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
RuntimeFungibleTokenTransferInterpreter-43.08k ± 0%3.08k ± 0%~(all equal)
RuntimeFungibleTokenTransferVM-43.61k ± 0%3.61k ± 0%~(all equal)
RuntimeResourceDictionaryValues-436.7k ± 0%36.7k ± 0%~(p=1.000 n=1+1)
RuntimeResourceTracking-4129k ± 0%129k ± 0%~(all equal)
RuntimeScriptNoop-4114 ± 0%114 ± 0%~(all equal)
RuntimeVMInvokeContractImperativeFib-4426 ± 0%426 ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ValueIsSubtypeOfSemaType-41.00 ± 0%1.00 ± 0%~(all equal)
 

@SupunS SupunS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for improving!

@SupunS
SupunS merged commit c5052d7 into master Apr 16, 2026
17 checks passed
@turbolent
turbolent deleted the holyfuchs/fix-readfile-error branch April 21, 2026 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test.readFile panics on file-not-found, producing a confusing internal error with full stack trace

2 participants

⌂ 换网址