Skip to content

Commit e7bcd79

Browse files
committed
Add debug messages
1 parent 2e8211e commit e7bcd79

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

lib/sourcebit.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ class Sourcebit {
6969
pluginBlock._isBootstrapped = true;
7070
}
7171

72+
debug(...parameters) {
73+
return this.getDebugMethodForCore().call(this, parameters);
74+
}
75+
7276
getContext() {
7377
return cloneDeep(this.context);
7478
}
@@ -77,6 +81,10 @@ class Sourcebit {
7781
return this.context[namespace] ? cloneDeep(this.context[namespace]) : {};
7882
}
7983

84+
getDebugMethodForCore() {
85+
return debug("core");
86+
}
87+
8088
getDebugMethodForPlugin(pluginName) {
8189
return debug(`plugin:${pluginName}`);
8290
}
@@ -93,7 +101,7 @@ class Sourcebit {
93101

94102
return JSON.parse(data);
95103
} catch (error) {
96-
console.log(error);
104+
this.debug(error);
97105
}
98106
}
99107

@@ -157,7 +165,7 @@ class Sourcebit {
157165
try {
158166
fs.writeFileSync(this.cacheFilePath, serializedCache);
159167
} catch (error) {
160-
console.log(error);
168+
this.debug(error);
161169
}
162170
}
163171

@@ -236,6 +244,13 @@ class Sourcebit {
236244

237245
return data;
238246
} catch (error) {
247+
this.log(
248+
`An error occurred when processing the plugins: ${error.message}.`,
249+
"fail"
250+
);
251+
252+
this.debug(error);
253+
239254
finishTransform();
240255

241256
if (typeof this.onTransform === "function") {
@@ -280,7 +295,8 @@ class Sourcebit {
280295
fs.unlinkSync(filePath);
281296

282297
this.log(`Deleted ${filePath}`, "info");
283-
} catch (_) {
298+
} catch (error) {
299+
this.debug(error);
284300
this.log(`Could not delete ${filePath}`, "fail");
285301
}
286302
}
@@ -311,7 +327,8 @@ class Sourcebit {
311327
this.log(`Created ${filePath}`, "succeed");
312328

313329
return true;
314-
} catch (_) {
330+
} catch (error) {
331+
this.debug(error);
315332
this.log(`Could not create ${filePath}`, "fail");
316333

317334
return false;

0 commit comments

Comments
 (0)