🚸 allow errors parsing config.json to be thrown
This commit is contained in:
parent
d4d1a8eec9
commit
4c13ac753b
4 changed files with 57 additions and 79 deletions
|
|
@ -16,15 +16,11 @@ export class ConfigHandler {
|
|||
private savedConfig: ContinueConfig | undefined;
|
||||
private savedBrowserConfig?: BrowserSerializedContinueConfig;
|
||||
|
||||
private readonly ide: IDE;
|
||||
private ideSettingsPromise: Promise<IdeSettings>;
|
||||
private readonly writeLog: (text: string) => void;
|
||||
private readonly onConfigUpdate: () => void;
|
||||
constructor(
|
||||
ide: IDE,
|
||||
ideSettingsPromise: Promise<IdeSettings>,
|
||||
writeLog: (text: string) => void,
|
||||
onConfigUpdate: () => void,
|
||||
private readonly ide: IDE,
|
||||
private ideSettingsPromise: Promise<IdeSettings>,
|
||||
private readonly writeLog: (text: string) => void,
|
||||
private readonly onConfigUpdate: () => void,
|
||||
) {
|
||||
this.ide = ide;
|
||||
this.ideSettingsPromise = ideSettingsPromise;
|
||||
|
|
@ -58,50 +54,45 @@ export class ConfigHandler {
|
|||
}
|
||||
|
||||
async loadConfig(): Promise<ContinueConfig> {
|
||||
try {
|
||||
if (this.savedConfig) {
|
||||
return this.savedConfig;
|
||||
}
|
||||
|
||||
let workspaceConfigs: ContinueRcJson[] = [];
|
||||
try {
|
||||
workspaceConfigs = await this.ide.getWorkspaceConfigs();
|
||||
} catch (e) {
|
||||
console.warn("Failed to load workspace configs");
|
||||
}
|
||||
|
||||
const ideInfo = await this.ide.getIdeInfo();
|
||||
const ideSettings = await this.ideSettingsPromise;
|
||||
let remoteConfigServerUrl = undefined;
|
||||
try {
|
||||
remoteConfigServerUrl =
|
||||
typeof ideSettings.remoteConfigServerUrl !== "string" ||
|
||||
ideSettings.remoteConfigServerUrl === ""
|
||||
? undefined
|
||||
: new URL(ideSettings.remoteConfigServerUrl);
|
||||
} catch (e) {}
|
||||
|
||||
this.savedConfig = await loadFullConfigNode(
|
||||
this.ide.readFile,
|
||||
workspaceConfigs,
|
||||
remoteConfigServerUrl,
|
||||
ideInfo.ideType,
|
||||
);
|
||||
this.savedConfig.allowAnonymousTelemetry =
|
||||
this.savedConfig.allowAnonymousTelemetry &&
|
||||
(await this.ide.isTelemetryEnabled());
|
||||
|
||||
// Setup telemetry only after (and if) we know it is enabled
|
||||
await Telemetry.setup(
|
||||
this.savedConfig.allowAnonymousTelemetry ?? true,
|
||||
await this.ide.getUniqueId(),
|
||||
);
|
||||
|
||||
if (this.savedConfig) {
|
||||
return this.savedConfig;
|
||||
} catch (e: any) {
|
||||
console.error("Failed to loadConfig: ", e.message);
|
||||
throw new Error("Failed to loadConfig: " + e.message);
|
||||
}
|
||||
|
||||
let workspaceConfigs: ContinueRcJson[] = [];
|
||||
try {
|
||||
workspaceConfigs = await this.ide.getWorkspaceConfigs();
|
||||
} catch (e) {
|
||||
console.warn("Failed to load workspace configs");
|
||||
}
|
||||
|
||||
const ideInfo = await this.ide.getIdeInfo();
|
||||
const ideSettings = await this.ideSettingsPromise;
|
||||
let remoteConfigServerUrl = undefined;
|
||||
try {
|
||||
remoteConfigServerUrl =
|
||||
typeof ideSettings.remoteConfigServerUrl !== "string" ||
|
||||
ideSettings.remoteConfigServerUrl === ""
|
||||
? undefined
|
||||
: new URL(ideSettings.remoteConfigServerUrl);
|
||||
} catch (e) {}
|
||||
|
||||
this.savedConfig = await loadFullConfigNode(
|
||||
this.ide.readFile,
|
||||
workspaceConfigs,
|
||||
remoteConfigServerUrl,
|
||||
ideInfo.ideType,
|
||||
);
|
||||
this.savedConfig.allowAnonymousTelemetry =
|
||||
this.savedConfig.allowAnonymousTelemetry &&
|
||||
(await this.ide.isTelemetryEnabled());
|
||||
|
||||
// Setup telemetry only after (and if) we know it is enabled
|
||||
await Telemetry.setup(
|
||||
this.savedConfig.allowAnonymousTelemetry ?? true,
|
||||
await this.ide.getUniqueId(),
|
||||
);
|
||||
|
||||
return this.savedConfig;
|
||||
}
|
||||
|
||||
setupLlm(llm: ILLM): ILLM {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ import {
|
|||
getContinueDotEnv,
|
||||
migrate,
|
||||
} from "../util/paths";
|
||||
import { defaultConfig } from "./default";
|
||||
const { execSync } = require("child_process");
|
||||
|
||||
function resolveSerializedConfig(filepath: string): SerializedContinueConfig {
|
||||
|
|
@ -80,8 +79,7 @@ function loadSerializedConfig(
|
|||
try {
|
||||
config = resolveSerializedConfig(configPath);
|
||||
} catch (e) {
|
||||
console.log("config.json is invalid. Falling back to default.");
|
||||
config = defaultConfig;
|
||||
throw new Error(`Failed to parse config.json: ${e}`);
|
||||
}
|
||||
|
||||
if (config.allowAnonymousTelemetry === undefined) {
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ export class VsCodeWebviewProtocol {
|
|||
JSON.stringify({ msg }, null, 2),
|
||||
);
|
||||
|
||||
let message = `Continue error: ${e.message}`;
|
||||
let message = e.message;
|
||||
if (e.cause) {
|
||||
if (e.cause.name === "ConnectTimeoutError") {
|
||||
message = `Connection timed out. If you expect it to take a long time to connect, you can increase the timeout in config.json by setting "requestOptions": { "timeout": 10000 }. You can find the full config reference here: https://continue.dev/docs/reference/config`;
|
||||
|
|
|
|||
|
|
@ -97,18 +97,7 @@ const initialState: State = {
|
|||
contextItems: [],
|
||||
active: false,
|
||||
config: {
|
||||
models: [
|
||||
{
|
||||
title: "GPT-4 (Free Trial)",
|
||||
model: "gpt-4",
|
||||
provider: "free-trial",
|
||||
},
|
||||
{
|
||||
title: "GPT-3.5-Turbo (Free Trial)",
|
||||
model: "gpt-3.5-turbo",
|
||||
provider: "free-trial",
|
||||
},
|
||||
],
|
||||
models: [],
|
||||
slashCommands: [
|
||||
{
|
||||
name: "edit",
|
||||
|
|
@ -140,7 +129,7 @@ export const stateSlice = createSlice({
|
|||
reducers: {
|
||||
setConfig: (
|
||||
state,
|
||||
{ payload: config }: PayloadAction<BrowserSerializedContinueConfig>
|
||||
{ payload: config }: PayloadAction<BrowserSerializedContinueConfig>,
|
||||
) => {
|
||||
const defaultModelTitle =
|
||||
config.models.find((model) => model.title === state.defaultModelTitle)
|
||||
|
|
@ -168,7 +157,7 @@ export const stateSlice = createSlice({
|
|||
}: PayloadAction<{
|
||||
index: number;
|
||||
contextItems: ChatHistoryItem["contextItems"];
|
||||
}>
|
||||
}>,
|
||||
) => {
|
||||
if (state.history[index]) {
|
||||
state.history[index].contextItems = contextItems;
|
||||
|
|
@ -178,7 +167,7 @@ export const stateSlice = createSlice({
|
|||
state,
|
||||
{
|
||||
payload: { index, item },
|
||||
}: PayloadAction<{ index?: number; item: ContextItemWithId }>
|
||||
}: PayloadAction<{ index?: number; item: ContextItemWithId }>,
|
||||
) => {
|
||||
if (index === undefined) {
|
||||
const isFirstContextItem =
|
||||
|
|
@ -201,7 +190,7 @@ export const stateSlice = createSlice({
|
|||
}: PayloadAction<{
|
||||
index: number;
|
||||
editorState: JSONContent;
|
||||
}>
|
||||
}>,
|
||||
) => {
|
||||
const historyItem = state.history[payload.index];
|
||||
if (!historyItem) {
|
||||
|
|
@ -228,7 +217,7 @@ export const stateSlice = createSlice({
|
|||
payload,
|
||||
}: PayloadAction<{
|
||||
editorState: JSONContent;
|
||||
}>
|
||||
}>,
|
||||
) => {
|
||||
state.history.push({
|
||||
message: { role: "user", content: "" },
|
||||
|
|
@ -253,7 +242,7 @@ export const stateSlice = createSlice({
|
|||
message: ChatMessage;
|
||||
index: number;
|
||||
contextItems?: ContextItemWithId[];
|
||||
}>
|
||||
}>,
|
||||
) => {
|
||||
if (payload.index >= state.history.length) {
|
||||
state.history.push({
|
||||
|
|
@ -281,7 +270,7 @@ export const stateSlice = createSlice({
|
|||
}: PayloadAction<{
|
||||
index: number;
|
||||
contextItems: ContextItemWithId[];
|
||||
}>
|
||||
}>,
|
||||
) => {
|
||||
const historyItem = state.history[payload.index];
|
||||
if (!historyItem) {
|
||||
|
|
@ -300,7 +289,7 @@ export const stateSlice = createSlice({
|
|||
},
|
||||
newSession: (
|
||||
state,
|
||||
{ payload }: PayloadAction<PersistedSessionInfo | undefined>
|
||||
{ payload }: PayloadAction<PersistedSessionInfo | undefined>,
|
||||
) => {
|
||||
if (payload) {
|
||||
state.history = payload.history;
|
||||
|
|
@ -318,14 +307,14 @@ export const stateSlice = createSlice({
|
|||
state,
|
||||
{
|
||||
payload,
|
||||
}: PayloadAction<{ ids: ContextItemId[]; index: number | undefined }>
|
||||
}: PayloadAction<{ ids: ContextItemId[]; index: number | undefined }>,
|
||||
) => {
|
||||
const getKey = (id: ContextItemId) => `${id.providerTitle}-${id.itemId}`;
|
||||
const ids = new Set(payload.ids.map(getKey));
|
||||
|
||||
if (payload.index === undefined) {
|
||||
state.contextItems = state.contextItems.filter(
|
||||
(item) => !ids.has(getKey(item.id))
|
||||
(item) => !ids.has(getKey(item.id)),
|
||||
);
|
||||
} else {
|
||||
state.history[payload.index].contextItems = state.history[
|
||||
|
|
@ -337,7 +326,7 @@ export const stateSlice = createSlice({
|
|||
state,
|
||||
{
|
||||
payload,
|
||||
}: PayloadAction<{ rangeInFileWithContents: any; edit: boolean }>
|
||||
}: PayloadAction<{ rangeInFileWithContents: any; edit: boolean }>,
|
||||
) => {
|
||||
let contextItems = [...state.contextItems].map((item) => {
|
||||
return { ...item, editing: false };
|
||||
|
|
@ -400,7 +389,7 @@ export const stateSlice = createSlice({
|
|||
state,
|
||||
{
|
||||
payload,
|
||||
}: PayloadAction<{ ids: ContextItemId[]; index: number | undefined }>
|
||||
}: PayloadAction<{ ids: ContextItemId[]; index: number | undefined }>,
|
||||
) => {
|
||||
const ids = payload.ids.map((id) => id.itemId);
|
||||
|
||||
|
|
@ -436,7 +425,7 @@ export const stateSlice = createSlice({
|
|||
},
|
||||
setDefaultModel: (state, { payload }: PayloadAction<string>) => {
|
||||
const model = state.config.models.find(
|
||||
(model) => model.title === payload
|
||||
(model) => model.title === payload,
|
||||
);
|
||||
if (!model) return;
|
||||
return {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue