Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit 0a2bfb5

Browse files
committed
error handler and correct return for polyfill require
1 parent 1a09b0f commit 0a2bfb5

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Fixed polyfill require not resetting recursion detection when an error occurs
13+
- Fixed polyfill require not returning `":preload:"`
14+
1015
## [0.3.1] - 2022-02-04
1116

1217
### Added

luapack.yue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,14 @@ export class Packer
176176
writer\endwrap ->
177177
writer\writeln 'error(("module not found %q"):format(modname), 2)'
178178
writer\writeln "package.loaded[modname] = sentinel"
179-
writer\writeln 'local result = package.preload[modname](modname, ":preload:")'
179+
writer\writeln 'local success, result = pcall(package.preload[modname], modname, ":preload:")'
180+
writer\writeln "if not success then"
181+
writer\endwrap ->
182+
writer\writeln "package.loaded[modname] = nil" -- so it can be loaded again
183+
writer\writeln "error(result)" -- rethrow error
180184
writer\writeln "if result == nil then result = true end"
181185
writer\writeln "package.loaded[modname] = result"
182-
writer\writeln "return result"
186+
writer\writeln 'return result, ":preload:"'
183187

184188
already_loaded = {}
185189
for package_name, content in pairs @loaded

0 commit comments

Comments
 (0)