Skip to content

Commit

Permalink
Merge pull request #186 from chromaui/jarel/ap-4239-chromatic-addon-f…
Browse files Browse the repository at this point in the history
…ails-when-initializing-storybook-on-an

Only throw errors for Git messages after a Project ID has been set
  • Loading branch information
thafryer authored Feb 13, 2024
2 parents 76c64b9 + 1f27e41 commit d888b16
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
14 changes: 7 additions & 7 deletions src/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ export const Panel = ({ active, api }: PanelProps) => {
return withProviders(<Uninstalled />);
}

if (gitInfoError) {
// eslint-disable-next-line no-console
console.error(gitInfoError);
return withProviders(<GitNotFound gitInfoError={gitInfoError} />);
}

// Render the Authentication flow if the user is not signed in.
if (!accessToken) {
return withProviders(
Expand All @@ -102,7 +96,7 @@ export const Panel = ({ active, api }: PanelProps) => {
}

// Momentarily wait on addonState (should be very fast)
if (projectInfoLoading || !gitInfo) {
if (projectInfoLoading) {
return active ? <Spinner /> : null;
}

Expand All @@ -115,6 +109,12 @@ export const Panel = ({ active, api }: PanelProps) => {
/>
);

if (gitInfoError || !gitInfo) {
// eslint-disable-next-line no-console
console.error(gitInfoError);
return withProviders(<GitNotFound />);
}

if (projectUpdatingFailed) {
// These should always be set when we get this error
if (!configFile) throw new Error(`Missing config file after configuration failure`);
Expand Down
11 changes: 6 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ function managerEntries(entry: string[] = []) {
const observeGitInfo = async (
interval: number,
callback: (info: GitInfo, prevInfo?: GitInfo) => void,
errorCallback: (e: Error) => void
errorCallback: (e: Error) => void,
projectId?: string
) => {
let prev: GitInfo | undefined;
let prevError: Error | undefined;
Expand All @@ -47,12 +48,12 @@ const observeGitInfo = async (
prevError = undefined;
timer = setTimeout(act, interval);
} catch (e: any) {
if (prevError?.message !== e.message) {
errorCallback(e);
if (projectId && prevError?.message !== e.message) {
console.error(`Failed to fetch git info, with error:\n${e}`);
errorCallback(e);
prev = undefined;
prevError = e;
}
prev = undefined;
prevError = e;
timer = setTimeout(act, interval);
}
};
Expand Down
6 changes: 1 addition & 5 deletions src/screens/GitNotFound/GitNotFound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import { Stack } from "../../components/Stack";
import { Text } from "../../components/Text";
import { useUninstallAddon } from "../Uninstalled/UninstallContext";

interface GitNotFoundProps {
gitInfoError: Error;
}

const InfoSection = styled(Section)(({ theme }) => ({
display: "flex",
flexDirection: "row",
Expand All @@ -42,7 +38,7 @@ const StyledCode = styled(Code)(({ theme }) => ({
fontSize: "12px",
}));

export const GitNotFound = ({ gitInfoError }: GitNotFoundProps) => {
export const GitNotFound = () => {
const { uninstallAddon } = useUninstallAddon();
return (
<Screen footer={null}>
Expand Down

0 comments on commit d888b16

Please sign in to comment.