Skip to content

Commit

Permalink
fix: env variable issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bugwheels94 committed Jan 12, 2024
1 parent d8b93fb commit 2152c1c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/routes/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import yaml from 'js-yaml';
import { throttle, uniqBy } from 'lodash';
import { spawn } from 'node-pty';
import os from 'os';
import { Router, RouterResponse } from 'soxtend/server';
import { ApiError, Router, RouterResponse } from 'soxtend/server';
import kill from 'tree-kill';
import { AppDataSource, ProjectRepository, TerminalLogRepository, TerminalRepository } from '../data-source';
import { Terminal } from '../entity/Terminal';
Expand Down Expand Up @@ -97,12 +97,12 @@ export const addTerminalRoutes = (router: Router) => {
if (Object.keys(terminal).length === 0) return;
if (terminal.startupEnvironmentVariables) {
try {
yaml.load(terminal.startupEnvironmentVariables, {
const doc = yaml.load(terminal.startupEnvironmentVariables, {
schema: yaml.JSON_SCHEMA,
});
if (typeof doc !== 'object') throw new ApiError('Invalid YAML for startup Environment Variables', 400);
} catch (e) {
console.log('error', e);
throw new Error('Invalid YAML for startup Environment Variables');
throw new ApiError('Invalid YAML for startup Environment Variables', 400);
}
}
// This prevents from updating terminal object in the triggering app unnecessary.
Expand Down Expand Up @@ -217,7 +217,7 @@ function createPtyTerminal({
}) as Record<string, string>;
env = { ...(process.env as Record<string, string>), ...doc };
} catch (e) {
throw new Error('Invalid YAML for startup Environment Variables');
console.log(e);
}
let cwd = terminal.cwd;
if (cwd) {
Expand Down
6 changes: 4 additions & 2 deletions ui/src/pages/MyTerminal/MyTerminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { debounce } from 'lodash-es';
import { useCallback, useContext, useEffect, useMemo, useReducer } from 'react';
import { client } from '../../utils/socket';
import { Addons, createTerminal } from '../../utils/Terminal';
import { Drawer, Input, Modal, AutoComplete, Form } from 'antd';
import { Drawer, Input, Modal, AutoComplete, Form, Alert } from 'antd';
import './MyTerminal.css';

// @ts-ignore
Expand Down Expand Up @@ -130,7 +130,7 @@ export const MyTerminal = ({
mainCommandCounter: number;
}) => {
const [isPatching, setIsPatching] = useState(false);
const { mutate: patchTerminal } = usePatchTerminal(projectId, terminal.id);
const { mutate: patchTerminal, error } = usePatchTerminal(projectId, terminal.id);

const [editorCommand, setEditorCommand] = useState('');
const [isCommandSuggestionOpen, setIsCommandSuggestionOpen] = useState(false);
Expand Down Expand Up @@ -422,6 +422,7 @@ export const MyTerminal = ({
});
}, [searchValue, state]);
if (!state) return null;
console.log(error);
return (
<>
<Drawer open={!!executionScript} onClose={() => setExecutionScript(null)}>
Expand Down Expand Up @@ -568,6 +569,7 @@ export const MyTerminal = ({
>
<Input.TextArea placeholder="Yaml syntax(KEY: VALUE)" />
</Form.Item>
{error && <Alert message={error?.message} type="error" />}
</Form>
</Drawer>
</>
Expand Down
4 changes: 0 additions & 4 deletions ui/src/services/terminals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ export const usePatchTerminal = (
method: 'patch',
}),
{
retry: (_, error) => {
if (error.status === 401) return false;
return true;
},
...options,
}
);
Expand Down

0 comments on commit 2152c1c

Please sign in to comment.