Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/commands/db/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ export default function DbList() {

useEffect(() => {
(async () => {
const pc = readProjectConfig();
let pc: ReturnType<typeof readProjectConfig>;
try {
pc = readProjectConfig();
} catch (err) {
setError(err instanceof Error ? err.message : String(err));
setTimeout(() => exit(new Error()), 100);
return;
}
if (!pc) {
setError('This project is not initialized. Run "kiqr init" first.');
setTimeout(() => exit(new Error()), 100);
Expand Down
33 changes: 27 additions & 6 deletions src/commands/info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,39 @@ export const description = 'Show project info and credentials';
export default function Info() {
const {exit} = useApp();

const pc = readProjectConfig();
if (!pc) {
let result:
| {
ok: true;
pc: NonNullable<ReturnType<typeof readProjectConfig>>;
lc: ReturnType<typeof readLocalConfig>;
}
| {ok: false; message: string | null};
try {
const pc = readProjectConfig();
if (!pc) {
result = {ok: false, message: null};
} else {
const lc = readLocalConfig(getProjectRuntimeDir(pc.project_id));
result = {ok: true, pc, lc};
}
} catch (err) {
result = {ok: false, message: err instanceof Error ? err.message : String(err)};
}

if (!result.ok) {
const message =
result.message ?? 'This project is not initialized. Run "kiqr init" first.';
if (result.message !== null) {
setTimeout(() => exit(new Error(message)), 50);
}
return (
<Box paddingTop={1}>
<Text color="red">This project is not initialized. Run "kiqr init" first.</Text>
<Text color="red">{message}</Text>
</Box>
);
}

const runtimeDir = getProjectRuntimeDir(pc.project_id);
const lc = readLocalConfig(runtimeDir);

const {pc, lc} = result;
const hostname = buildProjectHostname(pc.name);
const phpMyAdminHostname = buildProjectHostname(pc.name, 'phpmyadmin');

Expand Down
9 changes: 8 additions & 1 deletion src/commands/logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ export default function Logs() {
const {exit} = useApp();

useEffect(() => {
const pc = readProjectConfig();
let pc: ReturnType<typeof readProjectConfig>;
try {
pc = readProjectConfig();
} catch (err) {
console.error(err instanceof Error ? err.message : String(err));
exit(new Error());
return;
}
if (!pc) {
console.error('This project is not initialized. Run "kiqr init" first.');
exit(new Error());
Expand Down
18 changes: 16 additions & 2 deletions src/commands/open.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ export default function Open({args}: Props) {
const [appArg] = args;

useEffect(() => {
const pc = readProjectConfig();
let pc: ReturnType<typeof readProjectConfig>;
try {
pc = readProjectConfig();
} catch (err) {
console.error(err instanceof Error ? err.message : String(err));
exit(new Error());
return;
}
if (!pc) {
console.error('This project is not initialized. Run "kiqr init" first.');
exit(new Error());
Expand All @@ -84,7 +91,14 @@ export default function Open({args}: Props) {
}

const runtimeDir = getProjectRuntimeDir(pc.project_id);
const lc = readLocalConfig(runtimeDir);
let lc: ReturnType<typeof readLocalConfig>;
try {
lc = readLocalConfig(runtimeDir);
} catch (err) {
console.error(err instanceof Error ? err.message : String(err));
exit(new Error());
return;
}
const hostname = buildProjectHostname(pc.name);
const phpMyAdminHostname = buildProjectHostname(pc.name, 'phpmyadmin');

Expand Down
8 changes: 7 additions & 1 deletion src/commands/watch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ export default function Watch() {
let mounted = true;

async function startWatch() {
const pc = readProjectConfig();
let pc: ReturnType<typeof readProjectConfig>;
try {
pc = readProjectConfig();
} catch (err) {
setError(err instanceof Error ? err.message : String(err));
return;
}
if (!pc) {
setError('This project is not initialized. Run "kiqr init" first.');
return;
Expand Down
Loading