Skip to content

forge compile --json does not emit valid JSON on invalid absolute import paths #11149

@mmsaki

Description

@mmsaki

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge Version: 1.2.3-stable Commit SHA: a813a2c Build Timestamp: 2025-06-08T15:42:50.507050000Z (1749397370) Build Profile: maxperf

What version of Foundryup are you on?

foundryup: 1.3.0

What command(s) is the bug in?

forge compile A.sol --json

Operating System

None

Describe the bug

forge compile --json fails to emit JSON when import path starts with /

Steps to Reproduce

Case 1: Invalid absolute import

File: A.sol

import {B} from "/badpath/B.sol"; contract A is B {}

Run:

forge compile A.sol --json

Output (non-JSON):

ERROR foundry_compilers_artifacts_solc::sources: error="/badpath/B.sol": No such file or directory (os error 2) Error: failed to resolve file: "/badpath/B.sol": No such file or directory (os error 2); check configured remappings --> ./A.sol /badpath/B.sol

Case 2: Invalid relative import

import {B} from "badpath/B.sol"; contract A {}

Output (valid JSON):

{ "errors": [ { "sourceLocation": { "file": "A.sol", "start": -1, "end": -1 }, ... } ] }

Issue

When an import path begins with /, forge compile --json fails to return valid JSON. This breaks tools that rely on consistent machine-readable output.

Expected Behavior

forge compile --json should always return valid JSON, regardless of import path formatting or resolution errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions