Skip to content

Commit abc6a52

Browse files
committed
refactor: improve error handling and code clarity in Alembic parsing logic
- Removed hardcoded sensitive data (`host`, `username`, `api_token`, `domain_name`) from `dist/index.js` and `lib/index.js`. - Enhanced `parseAndCheckAlembic` function to handle errors gracefully: - Added try-catch block for better error logging. - Improved handling of cases with no output from the response. - Replaced redundant JSON parsing with direct property access for the `response.output`. - Streamlined log messages for better clarity during Alembic checks. - Updated TypeScript typings in `src/index.ts` for `parseAndCheckAlembic` to use more accurate types.
1 parent 1160f13 commit abc6a52

3 files changed

Lines changed: 47 additions & 38 deletions

File tree

dist/index.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4242
return (mod && mod.__esModule) ? mod : { "default": mod };
4343
};
4444
Object.defineProperty(exports, "__esModule", ({ value: true }));
45-
const host = "www.pythonanywhere.com";
46-
const username = "electricchecker";
47-
const api_token = "29424564073e9d4bf07d420e09d5788c5bacf6f9";
48-
const domain_name = "electricchecker.pythonanywhere.com";
4945
const core = __importStar(__nccwpck_require__(2186));
5046
const axios_1 = __importDefault(__nccwpck_require__(8757));
5147
/**
@@ -172,19 +168,25 @@ function performPostRequest(requestUrl, payload, token) {
172168
}
173169
function parseAndCheckAlembic(response) {
174170
return __awaiter(this, void 0, void 0, function* () {
175-
const parsedData = JSON.parse(response);
176-
const output = parsedData.output;
177-
if (!output) {
178-
return false;
179-
}
180-
const lines = output.split("\r\n").filter((line) => line.trim() !== "");
181-
const alembicFound = lines.some((line) => line.includes("**Alembic found**"));
182-
if (alembicFound) {
183-
console.log("Alembic found!");
184-
return true;
171+
try {
172+
const output = response.output;
173+
if (!output) {
174+
console.log("No output found in the response.");
175+
return false;
176+
}
177+
const lines = output.split("\r\n").filter((line) => line.trim() !== "");
178+
const alembicFound = lines.some((line) => line.includes("**Alembic found**"));
179+
if (alembicFound) {
180+
console.log("Alembic found!");
181+
return true;
182+
}
183+
else {
184+
console.log("Alembic not found!");
185+
return false;
186+
}
185187
}
186-
else {
187-
console.log("Alembic not found!");
188+
catch (error) {
189+
console.error(`Error during Alembic check: ${error.message}`);
188190
return false;
189191
}
190192
});

lib/index.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3535
return (mod && mod.__esModule) ? mod : { "default": mod };
3636
};
3737
Object.defineProperty(exports, "__esModule", { value: true });
38-
const host = "www.pythonanywhere.com";
39-
const username = "electricchecker";
40-
const api_token = "29424564073e9d4bf07d420e09d5788c5bacf6f9";
41-
const domain_name = "electricchecker.pythonanywhere.com";
4238
const core = __importStar(require("@actions/core"));
4339
const axios_1 = __importDefault(require("axios"));
4440
/**
@@ -165,19 +161,25 @@ function performPostRequest(requestUrl, payload, token) {
165161
}
166162
function parseAndCheckAlembic(response) {
167163
return __awaiter(this, void 0, void 0, function* () {
168-
const parsedData = JSON.parse(response);
169-
const output = parsedData.output;
170-
if (!output) {
171-
return false;
172-
}
173-
const lines = output.split("\r\n").filter((line) => line.trim() !== "");
174-
const alembicFound = lines.some((line) => line.includes("**Alembic found**"));
175-
if (alembicFound) {
176-
console.log("Alembic found!");
177-
return true;
164+
try {
165+
const output = response.output;
166+
if (!output) {
167+
console.log("No output found in the response.");
168+
return false;
169+
}
170+
const lines = output.split("\r\n").filter((line) => line.trim() !== "");
171+
const alembicFound = lines.some((line) => line.includes("**Alembic found**"));
172+
if (alembicFound) {
173+
console.log("Alembic found!");
174+
return true;
175+
}
176+
else {
177+
console.log("Alembic not found!");
178+
return false;
179+
}
178180
}
179-
else {
180-
console.log("Alembic not found!");
181+
catch (error) {
182+
console.error(`Error during Alembic check: ${error.message}`);
181183
return false;
182184
}
183185
});

src/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,13 @@ async function performPostRequest(requestUrl: string, payload: any, token?: stri
135135
}
136136
}
137137

138-
async function parseAndCheckAlembic(response: string): Promise<any>{
139-
const parsedData = JSON.parse(response);
140-
const output: string = parsedData.output;
138+
async function parseAndCheckAlembic(response: any): Promise<boolean> {
139+
try {
140+
const output: string = response.output;
141141

142142
if (!output) {
143-
return false
143+
console.log("No output found in the response.");
144+
return false;
144145
}
145146

146147
const lines = output.split("\r\n").filter((line) => line.trim() !== "");
@@ -149,12 +150,16 @@ async function parseAndCheckAlembic(response: string): Promise<any>{
149150

150151
if (alembicFound) {
151152
console.log("Alembic found!");
152-
return true
153+
return true;
153154
} else {
154155
console.log("Alembic not found!");
155-
return false
156+
return false;
156157
}
158+
} catch (error: any) {
159+
console.error(`Error during Alembic check: ${error.message}`);
160+
return false;
157161
}
162+
}
158163

159164
async function setupConsole(baseConsoleUrl: string, api_token: string): Promise<any> {
160165
try {

0 commit comments

Comments
 (0)