- raiseIfErr traps the JS error sentinel (\x01FNERR:) and raises a catchable
PRG runtime error instead of handing back undefined/{error} as data.
- __GET__/__SET__ methods: explicit data read/write with existence +
writability (getter-only/non-writable/non-extensible) checks.
- per-VM lastErr (FN_LASTERROR) so parallel requests don't cross messages.
- capi/napi_errtest.prg exercises the 4 cases via BEGIN SEQUENCE/RECOVER USING.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
60 lines
1.7 KiB
Plaintext
60 lines
1.7 KiB
Plaintext
FUNCTION FN_HANDLE()
|
|
LOCAL oM := FN_REQUIRE( "/Users/charleskwon/fivenode/fivenode/fivenode/napi/test/errmod" )
|
|
LOCAL aRes := {}
|
|
LOCAL oErr
|
|
IF ! HB_ISOBJECT( oM )
|
|
RETURN hb_jsonEncode( { "err" => FN_LASTERROR() } )
|
|
ENDIF
|
|
|
|
// 1) 없는 method (미등록 → VM 오류, 이제 오류 객체로 잡힘)
|
|
BEGIN SEQUENCE
|
|
oM:nosuchmethod()
|
|
RECOVER USING oErr
|
|
AADD( aRes, "1 missing_method: " + ErrInfo( oErr ) )
|
|
END SEQUENCE
|
|
|
|
// 2) 없는 data 읽기
|
|
BEGIN SEQUENCE
|
|
oM:__get__( "nope" )
|
|
RECOVER USING oErr
|
|
AADD( aRes, "2 missing_read: " + ErrInfo( oErr ) )
|
|
END SEQUENCE
|
|
|
|
// 3) protected(getter-only) 쓰기
|
|
BEGIN SEQUENCE
|
|
oM:__set__( "readonly", 99 )
|
|
RECOVER USING oErr
|
|
AADD( aRes, "3 protected_write: " + ErrInfo( oErr ) )
|
|
END SEQUENCE
|
|
|
|
// 3b) 없는 data 쓰기
|
|
BEGIN SEQUENCE
|
|
oM:__set__( "nope", 1 )
|
|
RECOVER USING oErr
|
|
AADD( aRes, "3b missing_write: " + ErrInfo( oErr ) )
|
|
END SEQUENCE
|
|
|
|
// 4) type 틀림 / throw (boom 은 등록된 메서드 → 브리지 경유)
|
|
BEGIN SEQUENCE
|
|
oM:boom()
|
|
RECOVER USING oErr
|
|
AADD( aRes, "4 type_error: " + ErrInfo( oErr ) )
|
|
END SEQUENCE
|
|
|
|
// 정상 read/write
|
|
AADD( aRes, "ok_read: " + hb_CStr( oM:__get__( "name" ) ) )
|
|
oM:__set__( "name", "changed" )
|
|
AADD( aRes, "ok_write: " + hb_CStr( oM:__get__( "name" ) ) )
|
|
|
|
RETURN hb_jsonEncode( { ;
|
|
"status" => 200, ;
|
|
"headers" => { "Content-Type" => "application/json" }, ;
|
|
"body" => hb_jsonEncode( aRes ) ;
|
|
} )
|
|
|
|
STATIC FUNCTION ErrInfo( oErr )
|
|
IF HB_ISOBJECT( oErr )
|
|
RETURN oErr:Description + " [op=" + hb_CStr( oErr:Operation ) + " gc=" + hb_ntos( oErr:GenCode ) + "]"
|
|
ENDIF
|
|
RETURN "NON-OBJECT: " + hb_CStr( oErr )
|