Skip to content
Closed
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
47 changes: 47 additions & 0 deletions FrontEnd/my-app/context/ConfigBoundaryContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use client';

import React, { Component, ErrorInfo, ReactNode } from 'react';
import { ConfigurationBoundaryError } from '../lib/env-boundary';

interface Props {
children: ReactNode;
fallbackBoundaryName: string;
}

interface State {
hasError: boolean;
errorMessage: string | null;
}

export class ConfigBoundaryGuard extends Component<Props, State> {
public state: State = {
hasError: false,
errorMessage: null
};

public static getDerivedStateFromError(error: Error): State {
if (error instanceof ConfigurationBoundaryError) {
return { hasError: true, errorMessage: error.message };
}
// Pass non-configuration exceptions to the global Next.js error handler
throw error;
}

public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
console.error("Configuration Boundary Intercepted:", error, errorInfo);
}

public render() {
if (this.state.hasError) {
return (
<div className="p-4 m-4 border border-red-800 bg-red-950/20 text-red-400 rounded-lg">
<h3>⚠️ Configuration Error</h3>
<p className="text-sm font-mono mt-1">{this.state.errorMessage}</p>
</div>
);
}

// Fixed: Properly accessing children via this.props
return this.props.children;
}
}
Empty file.
41 changes: 41 additions & 0 deletions FrontEnd/my-app/lib/env-boundary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export class ConfigurationBoundaryError extends Error {
constructor(public variableName: string, contextBoundary: string) {
super(`Configuration Error: [${contextBoundary}] Missing mandatory environment variable "${variableName}". Ensure it is specified in your .env configuration.`);
this.name = 'ConfigurationBoundaryError';
}
}

/**
* Validates and retrieves a target environment parameter at the active operational boundary.
* Prevents initialization crashes by throwing lazily only when requested.
*/
export const getEnvParamLazy = (
key: string,
boundaryName: string,
fallback?: string
): string => {
const value = process.env[key];

if (!value) {
if (fallback !== undefined) {
return fallback;
}
// Task Requirement: Lazy runtime validation per boundary instead of global crashes
throw new ConfigurationBoundaryError(key, boundaryName);
}

return value;
};

// ============================================================================
// On-Demand Boundary Context Mappings
// ============================================================================

export const getStellarNetworkConfig = () => ({
network: getEnvParamLazy('NEXT_PUBLIC_STELLAR_NETWORK', 'Stellar Network Connection', 'TESTNET'),
horizonUrl: getEnvParamLazy('NEXT_PUBLIC_HORIZON_URL', 'Stellar Network Connection')
});

export const getAnalyticsConfig = () => ({
sentryDsn: getEnvParamLazy('NEXT_PUBLIC_SENTRY_DSN', 'Observability Analytics Module')
});
1 change: 1 addition & 0 deletions FrontEnd/my-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Loading