Skip to content

Commit 603da1f

Browse files
committed
eslint: reduce log-noise, cleanup error codes
1 parent 4598319 commit 603da1f

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

Diff for: lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// this file will be glued to the top of the specific xy-server.js file
1+
// this file will be glued to the top of the specific xy-serve.js file
2+
const debug_serve = false;
23
const GracefulShutdownManager = require("@moebius/http-graceful-shutdown").GracefulShutdownManager;
34
const express = require("express");
45
const app = express();

Diff for: lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ app.post("/eslint/format", async (req, res) => {
99
const ESLintOverrideConfigFile = format_data.eslint_override_config_file;
1010

1111
if (!ESLintOverrideConfig && !ESLintOverrideConfigFile) {
12-
res.status(501).send("Error while formatting: No config provided");
12+
res.status(400).send("Error while formatting: No config provided");
1313
return;
1414
}
1515

1616
const filePath = format_data.file_path;
1717

1818
if (!filePath) {
19-
res.status(501).send("Error while formatting: No file path provided");
19+
res.status(400).send("Error while formatting: No file path provided");
2020
return;
2121
}
2222

@@ -41,8 +41,10 @@ app.post("/eslint/format", async (req, res) => {
4141
eval("ESLintOptions.overrideConfig = " + ESLintOverrideConfig);
4242
}
4343

44-
console.log("using options: " + JSON.stringify(ESLintOptions));
45-
console.log("format input: ", format_data.file_content);
44+
if (debug_serve) {
45+
console.log("using options: " + JSON.stringify(ESLintOptions));
46+
console.log("format input: ", format_data.file_content);
47+
}
4648

4749
const eslint = new ESLint(ESLintOptions);
4850

@@ -55,20 +57,22 @@ app.post("/eslint/format", async (req, res) => {
5557
// LintResult[] // https://eslint.org/docs/latest/developer-guide/nodejs-api#-lintresult-type
5658
const results = await eslint.lintText(format_data.file_content, lintTextOptions);
5759
if (results.length !== 1) {
58-
res.status(501).send("Error while formatting: Unexpected number of results: " + JSON.stringify(results));
60+
res.status(500).send("Error while formatting: Unexpected number of results: " + JSON.stringify(results));
5961
return;
6062
}
6163
const result = results[0];
62-
console.log("result: " + JSON.stringify(result));
64+
if (debug_serve) {
65+
console.log("result: " + JSON.stringify(result));
66+
}
6367
if (result.fatalErrorCount && result.fatalErrorCount > 0) {
64-
res.status(501).send("Fatal error while formatting: " + JSON.stringify(result.messages));
68+
res.status(500).send("Fatal error while formatting: " + JSON.stringify(result.messages));
6569
return;
6670
}
6771
const formatted = result.output || result.source || format_data.file_content;
6872
res.set("Content-Type", "text/plain");
6973
res.send(formatted);
7074
} catch (err) {
7175
console.log("error", err);
72-
res.status(501).send("Error while formatting: " + err);
76+
res.status(500).send("Error while formatting: " + err);
7377
}
7478
});

Diff for: lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ app.post("/prettier/format", (req, res) => {
2727
try {
2828
formatted_file_content = prettier.format(format_data.file_content, format_data.config_options);
2929
} catch(err) {
30-
res.status(501).send("Error while formatting: " + err);
30+
res.status(500).send("Error while formatting: " + err);
3131
return;
3232
}
3333
res.set("Content-Type", "text/plain");

Diff for: lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ app.post("/tsfmt/format", (req, res) => {
2525
res.set("Content-Type", "text/plain");
2626
res.send(resultMap.dest);
2727
}).catch(reason => {
28-
res.status(501).send(reason);
28+
res.status(500).send(reason);
2929
});
3030
});

Diff for: testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void verifyPrettierErrorMessageIsRelayed() throws Exception {
116116
new PrettierConfig(null, ImmutableMap.of("parser", "postcss")));
117117
try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) {
118118
stepHarness.testResourceExceptionMsg("npm/prettier/filetypes/scss/scss.dirty").isEqualTo(
119-
"Unexpected response status code at /prettier/format [HTTP 501] -- (Error while formatting: Error: Couldn't resolve parser \"postcss\")");
119+
"Unexpected response status code at /prettier/format [HTTP 500] -- (Error while formatting: Error: Couldn't resolve parser \"postcss\")");
120120
}
121121
}
122122
}

0 commit comments

Comments
 (0)