Skip to content

Commit

Permalink
Improve error message when functions:shell command fails due to missi…
Browse files Browse the repository at this point in the history
…ng project association. (#6088)

**Before**:

```
$ firebase functions:shell
Error: An unexpected error has occurred.
```

**After**:

```
$  firebase functions:shell
Error: No currently active project.
To run this command, you need to specify a project. You have two options:
- Run this command with --project <alias_or_project_id>.
- Set an active project by running firebase use --add, then rerun this command.
To list all the Firebase projects to which you have access, run firebase projects:list.
To learn about active projects for the CLI, visit https://firebase.google.com/docs/cli#project_aliases
```

Fixes #6070
  • Loading branch information
taeold authored Jul 15, 2023
1 parent 53b65d6 commit b41c6f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 25 deletions.
9 changes: 5 additions & 4 deletions src/functionsShellCommandAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import * as _ from "lodash";
import * as request from "request";
import * as util from "util";

import * as shell from "./emulator/functionsEmulatorShell";
import * as commandUtils from "./emulator/commandUtils";
import { FunctionsServer } from "./serve/functions";
import LocalFunction from "./localFunction";
import * as utils from "./utils";
import { logger } from "./logger";
import * as shell from "./emulator/functionsEmulatorShell";
import * as commandUtils from "./emulator/commandUtils";
import { EMULATORS_SUPPORTED_BY_FUNCTIONS, EmulatorInfo, Emulators } from "./emulator/types";
import { EmulatorHubClient } from "./emulator/hubClient";
import { resolveHostAndAssignPorts } from "./emulator/portUtils";
import { Options } from "./options";
import { Constants } from "./emulator/constants";
import { needProjectId } from "./projectUtils";

const serveFunctions = new FunctionsServer();

Expand All @@ -29,8 +30,8 @@ export const actionFunction = async (options: Options) => {
debugPort = commandUtils.parseInspectionPort(options);
}

utils.assertDefined(options.project);
const hubClient = new EmulatorHubClient(options.project);
needProjectId(options);
const hubClient = new EmulatorHubClient(options.project!);

let remoteEmulators: Record<string, EmulatorInfo> = {};
if (hubClient.foundHub()) {
Expand Down
21 changes: 0 additions & 21 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,21 +596,6 @@ export function thirtyDaysFromNow(): Date {
return new Date(Date.now() + THIRTY_DAYS_IN_MILLISECONDS);
}

/**
* See:
* https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions
*/
export function assertDefined<T>(val: T, message?: string): asserts val is NonNullable<T> {
if (val === undefined || val === null) {
throw new AssertionError({
message: message || `expected value to be defined but got "${val}"`,
});
}
}

/**
*
*/
export function assertIsString(val: any, message?: string): asserts val is string {
if (typeof val !== "string") {
throw new AssertionError({
Expand All @@ -619,9 +604,6 @@ export function assertIsString(val: any, message?: string): asserts val is strin
}
}

/**
*
*/
export function assertIsNumber(val: any, message?: string): asserts val is number {
if (typeof val !== "number") {
throw new AssertionError({
Expand All @@ -630,9 +612,6 @@ export function assertIsNumber(val: any, message?: string): asserts val is numbe
}
}

/**
*
*/
export function assertIsStringOrUndefined(
val: any,
message?: string
Expand Down

0 comments on commit b41c6f4

Please sign in to comment.