forked from stackblitz-labs/bolt.diy
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: catch errors from web container preview and show in actionable …
…alert so user can send them to AI for fixing (stackblitz-labs#856) * Catch errors from web container * Show fix error popup on errors in preview * Remove unneeded action type * PR comments * Cleanup urls in stacktrace --------- Co-authored-by: Anirban Kar <[email protected]>
- Loading branch information
Showing
5 changed files
with
69 additions
and
10 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
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,27 @@ | ||
/** | ||
* Cleans webcontainer URLs from stack traces to show relative paths instead | ||
*/ | ||
export function cleanStackTrace(stackTrace: string): string { | ||
// Function to clean a single URL | ||
const cleanUrl = (url: string): string => { | ||
const regex = /^https?:\/\/[^\/]+\.webcontainer-api\.io(\/.*)?$/; | ||
|
||
if (!regex.test(url)) { | ||
return url; | ||
} | ||
|
||
const pathRegex = /^https?:\/\/[^\/]+\.webcontainer-api\.io\/(.*?)$/; | ||
const match = url.match(pathRegex); | ||
|
||
return match?.[1] || ''; | ||
}; | ||
|
||
// Split the stack trace into lines and process each line | ||
return stackTrace | ||
.split('\n') | ||
.map((line) => { | ||
// Match any URL in the line that contains webcontainer-api.io | ||
return line.replace(/(https?:\/\/[^\/]+\.webcontainer-api\.io\/[^\s\)]+)/g, (match) => cleanUrl(match)); | ||
}) | ||
.join('\n'); | ||
} |