mirror of
https://github.com/morluto/rea.git
synced 2026-11-23 06:55:55 +00:00
fix(setup): attribute malformed environment keys to their source (#13522)
This commit is contained in:
1 parent
b6ffec43ad
commit
4657cdd219
4 files changed
+118
-102
No files matched your search
@@ -15,7 +15,10 @@ import {
|
||||
clientProjectConfigurationPaths,
|
||||
type SetupClient,
|
||||
} from "./SupportedClients.js";
|
||||
import { clientRegistrationEnvironment } from "./ClientRegistrationEnvironment.js";
|
||||
import {
|
||||
ClientRegistrationEnvironmentShapeError,
|
||||
clientRegistrationEnvironment,
|
||||
} from "./ClientRegistrationEnvironment.js";
|
||||
import type { ArtifactResourceScope } from "../resources/index.js";
|
||||
import type { ConfigurationError } from "../domain/configurationErrors.js";
|
||||
import { mergeEnvironmentOverrides } from "../process/snapshotEnvironment.js";
|
||||
@@ -1157,20 +1160,22 @@ const contributingEnvironmentSource = (
|
||||
): ClientConfigurationSource | undefined => {
|
||||
const normalize = (name: string): string =>
|
||||
platform === "win32" ? name.toUpperCase() : name;
|
||||
const rejected = new Set(
|
||||
error.settings.flatMap(({ setting }) => {
|
||||
const parts = setting.split(".");
|
||||
return [normalize(setting), normalize(parts.at(-1) ?? setting)];
|
||||
}),
|
||||
);
|
||||
const keys =
|
||||
error instanceof ClientRegistrationEnvironmentShapeError
|
||||
? error.invalidKeys
|
||||
: error.settings.map(({ setting }) => setting);
|
||||
const rejected = new Set(keys.map(normalize));
|
||||
const invalidMap =
|
||||
error instanceof ClientRegistrationEnvironmentShapeError &&
|
||||
keys.length === 0;
|
||||
return declarations.findLast(({ source, entry }) => {
|
||||
if (!isRecord(entry) || !Object.hasOwn(entry, source.environmentKey))
|
||||
return false;
|
||||
if (invalidMap) return true;
|
||||
const environment = entry[source.environmentKey];
|
||||
return (
|
||||
rejected.has(normalize(source.environmentKey)) ||
|
||||
(isRecord(environment) &&
|
||||
Object.keys(environment).some((key) => rejected.has(normalize(key))))
|
||||
isRecord(environment) &&
|
||||
Object.keys(environment).some((key) => rejected.has(normalize(key)))
|
||||
);
|
||||
})?.source;
|
||||
};
|
||||
|
||||
@@ -85,6 +85,25 @@ const environmentSchema = clientConfigurationRecordSchema.transform(
|
||||
},
|
||||
);
|
||||
|
||||
/** Invalid recorded shape, with literal environment keys kept for source attribution. */
|
||||
export class ClientRegistrationEnvironmentShapeError extends ConfigurationError {
|
||||
constructor(
|
||||
field: string,
|
||||
readonly invalidKeys: readonly string[],
|
||||
) {
|
||||
super("Invalid REA server environment", {
|
||||
settings: (invalidKeys.length === 0
|
||||
? [field]
|
||||
: invalidKeys.map((key) => `${field}.${key}`)
|
||||
).map((setting) => ({
|
||||
setting,
|
||||
constraint:
|
||||
"Server environment must be an object containing only string values",
|
||||
})),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clients that expand `$VAR` and `${VAR}` in a recorded `env` value from the
|
||||
* environment the client itself runs with.
|
||||
@@ -164,17 +183,12 @@ export const clientRegistrationEnvironmentDetails = (
|
||||
const existing = environmentSchema.safeParse(raw === undefined ? {} : raw);
|
||||
if (!existing.success)
|
||||
return err(
|
||||
new ConfigurationError("Invalid REA server environment", {
|
||||
settings: existing.error.issues.map((issue) => ({
|
||||
setting: [
|
||||
...(source.nested ? ["transport"] : []),
|
||||
field.value,
|
||||
...issue.path,
|
||||
].join("."),
|
||||
constraint:
|
||||
"Server environment must be an object containing only string values",
|
||||
})),
|
||||
}),
|
||||
new ClientRegistrationEnvironmentShapeError(
|
||||
source.nested ? `transport.${field.value}` : field.value,
|
||||
existing.error.issues.flatMap(({ path: [key] }) =>
|
||||
typeof key === "string" ? [key] : [],
|
||||
),
|
||||
),
|
||||
);
|
||||
// Validate known settings with the runtime's parser, but retain the original
|
||||
// string overrides, including unknown client-specific keys and no defaults.
|
||||
|
||||
Reference in new issue
Block a user