Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/lib/plugins/uv/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,16 @@ function createDepgraphError(detail: string): CustomError {
}

function extractErrorDetail(result: GoCommandResult): string {
if (result.stdout) {
try {
const parsed = JSON.parse(result.stdout);
if (parsed.error) {
return parsed.error;
for (const output of [result.stderr, result.stdout]) {
if (output) {
try {
const parsed = JSON.parse(output);
if (parsed.error) {
return parsed.error;
}
} catch {
// not valid JSON; try next source, or fall back to returning plain stderr
}
} catch {
// stdout wasn't valid JSON; fall through to stderr
}
}
return result.stderr || 'Unable to process dependency information';
Expand Down
20 changes: 20 additions & 0 deletions src/lib/plugins/uv/uv.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,26 @@ describe('uv plugin', () => {
expect(err.message).toBe('something went wrong');
});

it('extracts error message from JSON in stderr when stdout is empty', async () => {
const stderrJson = JSON.stringify({
ok: false,
error:
'uv.lock is out of sync with pyproject.toml. Run `uv lock` to update the lockfile.',
path: '/test',
});
execGoCommandSpy.mockResolvedValueOnce(mockResult('', 2, stderrJson));

const err: CustomError = await inspect('.', 'uv.lock').catch((e) => e);

expect(err).toBeInstanceOf(CustomError);
expect(err.userMessage).toBe(
'uv.lock is out of sync with pyproject.toml. Run `uv lock` to update the lockfile.',
);
expect(err.message).toBe(
'uv.lock is out of sync with pyproject.toml. Run `uv lock` to update the lockfile.',
);
});

it('attaches an error catalog entry for IPC propagation', async () => {
const jsonError = JSON.stringify({
ok: false,
Expand Down
Loading