Skip to content

Commit 8f3c3a9

Browse files
committed
JavaScript: Include NPM error in marker details
1 parent 90ec374 commit 8f3c3a9

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

rewrite-javascript/rewrite/src/javascript/package-manager.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,21 @@ export async function runInstallInTempDir(
533533
});
534534

535535
if (!result.success) {
536+
// Combine error message with stderr for more useful diagnostics
537+
const errorParts: string[] = [];
538+
if (result.error) {
539+
errorParts.push(result.error);
540+
}
541+
if (result.stderr) {
542+
// Trim and limit stderr to avoid excessively long error messages
543+
const stderr = result.stderr.trim();
544+
if (stderr) {
545+
errorParts.push(stderr.length > 2000 ? stderr.slice(0, 2000) + '...' : stderr);
546+
}
547+
}
536548
return {
537549
success: false,
538-
error: result.error || result.stderr || 'Unknown error'
550+
error: errorParts.length > 0 ? errorParts.join('\n\n') : 'Unknown error'
539551
};
540552
}
541553

rewrite-javascript/rewrite/src/print.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import {Marker, MarkersKind, SearchResult} from "./markers";
16+
import {Marker, MarkersKind, Markup, SearchResult} from "./markers";
1717
import {Cursor, isSourceFile, SourceFile, Tree} from "./tree";
1818
import {TreeVisitor} from "./visitor";
1919
import {trimIndent} from "./util";
@@ -35,7 +35,11 @@ export namespace MarkerPrinter {
3535
let searchResult = marker as SearchResult;
3636
return commentWrapper(searchResult.description == null ? "" : "(" + searchResult.description + ")");
3737
} else if (marker.kind.startsWith("org.openrewrite.marker.Markup$")) {
38-
return commentWrapper("(" + (marker as any).message + ")");
38+
const markup = marker as Markup;
39+
const content = markup.detail
40+
? `(${markup.message}: ${markup.detail})`
41+
: `(${markup.message})`;
42+
return commentWrapper(content);
3943
}
4044
return "";
4145
},

0 commit comments

Comments
 (0)