Skip to content

Commit

Permalink
Fix extension crash when there is no root folder. (#8055)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuchenshi authored Dec 12, 2024
1 parent f98ffe4 commit c3896ad
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions firebase-vscode/src/logger-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,37 @@ export function logSetup() {

// Log to file
// Only log to file if firebase.debug extension setting is true.
// Re-implement file logger call from ../../src/bin/firebase.ts to not bring
// in the entire firebase.ts file
const rootFolders = getRootFolders();
// Default to a central path, but write files to a local path if we're in a Firebase directory.
let filePath = path.join(os.homedir(), ".cache", "firebase", "logs", "vsce-debug.log");
if (fs.existsSync(path.join(rootFolders[0], "firebase.json"))) {
filePath = path.join(rootFolders[0], ".firebase", "logs", "vsce-debug.log");
}
pluginLogger.info("Logging to path", filePath);
cliLogger.add(
new transports.File({
level: "debug",
filename: filePath,
format: format.printf((info) => {
const segments = [info.message, ...(info[SPLAT] || [])].map(
tryStringify,
);
return `[${info.level}] ${stripVTControlCharacters(segments.join(" "))}`;
}),
// Re-implement file logger call from ../../src/bin/firebase.ts to not bring
// in the entire firebase.ts file
const rootFolders = getRootFolders();
// Default to a central path, but write files to a local path if we're in a Firebase directory.
let filePath = path.join(
os.homedir(),
".cache",
"firebase",
"logs",
"vsce-debug.log",
);
if (
rootFolders.length > 0 &&
fs.existsSync(path.join(rootFolders[0], "firebase.json"))
) {
filePath = path.join(rootFolders[0], ".firebase", "logs", "vsce-debug.log");
}
pluginLogger.info("Logging to path", filePath);
cliLogger.add(
new transports.File({
level: "debug",
filename: filePath,
format: format.printf((info) => {
const segments = [info.message, ...(info[SPLAT] || [])].map(
tryStringify,
);
return `[${info.level}] ${stripVTControlCharacters(segments.join(" "))}`;
}),
);
cliLogger.add(new VSCodeOutputTransport({ level: "info" }));
}),
);
cliLogger.add(new VSCodeOutputTransport({ level: "info" }));
}

/**
Expand Down

0 comments on commit c3896ad

Please sign in to comment.