-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1506 from redpanda-data/nf/better-error
rpcn: pretty print linter errors on update
- Loading branch information
Showing
3 changed files
with
39 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Text } from '@redpanda-data/ui'; | ||
import { ConnectError } from '@connectrpc/connect'; | ||
import { LintHint } from '../../../protogen/redpanda/api/common/v1/linthint_pb'; | ||
|
||
export function formatPipelineError( | ||
err: any, | ||
): any { | ||
const details = []; | ||
let genDesc = String(err); | ||
if (err instanceof ConnectError) { | ||
genDesc = err.message; | ||
for (const detail of err.details) { | ||
if (isLintHint(detail)) { | ||
const hint = LintHint.fromJsonString(JSON.stringify(detail.debug)); | ||
details.push(`Line ${hint.line}, Col ${hint.column}: ${hint.hint}`) | ||
} | ||
} | ||
} | ||
let desc = <Text as="span">{genDesc}</Text> | ||
if (details.length > 0) { | ||
desc = <> | ||
<Text as="span">{genDesc}</Text> | ||
<ul> | ||
{details.map((d, idx) => ( | ||
<li style={{ listStylePosition: 'inside' }} key={idx}>{d}</li> | ||
))} | ||
</ul> | ||
</> | ||
} | ||
return desc | ||
} | ||
|
||
function isLintHint(obj: any): obj is { type: string, debug: any } { | ||
return obj && obj.type === LintHint.typeName; | ||
} |