Skip to content

Fix import! to throw error when target file/library is not found#159

Open
ermijeremy wants to merge 1 commit into
trueagi-io:mainfrom
ermijeremy:fix/erro_throw_on_import_not_found
Open

Fix import! to throw error when target file/library is not found#159
ermijeremy wants to merge 1 commit into
trueagi-io:mainfrom
ermijeremy:fix/erro_throw_on_import_not_found

Conversation

@ermijeremy
Copy link
Copy Markdown
Contributor

Description

Summary

This PR changes the import execution path so missing files/library targets raise a real Prolog exception instead of failing by backtracking to false.

Root Cause

import! previously swallowed all importer failures:

'import!'(Space, File, true) :- catch(importer_helper(Space, File), _, fail).

Implementation Details

The change removes blanket exception swallowing and makes failure explicit.

import! now directly delegates to importer_helper/2:

'import!'(Space, File, true) :- importer_helper(Space, File).

resolution now follows:

  1. Build candidate path (Path)
  2. Normalize extension with ensure_metta_ext/2 -> PathWithExt
  3. If file exists, load via load_metta_file/3
  4. Otherwise, throw:
throw(error(existence_error(source_sink, File),
            context('import!', File)))

This yields standard SWI-Prolog error semantics and is catch-compatible.

For valid imports, behavior is unchanged:
path resolution
.metta extension normalization
loading into the target space

Before

 Missing import: silent fail (`false`)

After

Missing import: explicit runtime error (`existence_error(source_sink, ...)`)
`catch` receives a concrete error term and can handle/report it

Validation

`!(catch (import! ...missing...))` returns structured `Error(...)` value as expected.

@patham9 patham9 added the Import label May 9, 2026
@patham9 patham9 added this to the v1.1 milestone May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants