Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

labelValueProvider type cast problem in resolvePath #1532

Open
bashleigh opened this issue Feb 25, 2025 · 1 comment
Open

labelValueProvider type cast problem in resolvePath #1532

bashleigh opened this issue Feb 25, 2025 · 1 comment

Comments

@bashleigh
Copy link

Hello, I wanted to make a log of this issue I've had that is related to this package. It looks like the function labelValueProvider is defined as returning either string or undefined. Later the returned value of labelValueProvider is being cast as a string and then length is being using against the same value.

export const resolvedPath = (
resolvedPath: string,
input: unknown,
memberName: string,
labelValueProvider: () => string | undefined,
uriLabel: string,
isGreedyLabel: boolean
): string => {
if (input != null && (input as Record<string, unknown>)[memberName] !== undefined) {
const labelValue = labelValueProvider() as string;
if (labelValue.length <= 0) {

I've not looked too much into this problem as I have some compiling complexities making this issue difficult to trace. In my issue I'm having a problem on line 16 where Cannot read properties of null (reading 'length') is the result. So I'm thinking labelValueProvider returns string, undefined or null?

I'm having this problem where @smithy/core is being used by @aws-sdk/client-cloudfront and my request looks as follows

const cloudfrontClient = new CloudFrontClient({})

const distroResult = await this.cloudfrontClient.send(
  new GetDistributionCommand({
    Id: 'myCloudfrontDistroId', // could potentially be undefined?
  }),
)

granted, my problem could be my implementation and not recieving the correct error?

I'm going to dig deeper into my issue, it would appear for now that the issue was introduced from our updating to ^3.675.0 potentially and persists in my upadting to ^3.750.0. However, regardless I would recommend the condition be improved for type safety and avoid the type casting.

const labelValue = labelValueProvider();
if (!labelValue || labelValue.length <= 0) {

I'm using node 18 within a lambda and heavily compiling the code using tsup and I reckon the problem could be a result of the complexity of compiling the typescript with tsup and configs. Wanted to bring the type casting issue to your attention though. Hopefully this makes sense and is helpful to someone

@bashleigh
Copy link
Author

After debugging I've realised the value I'm using within the GetDistributionCommand was in fact null. So I reckon the value being passed to the function is potentially null and being type cast as string? I'm not too clued up on this package so couldn't say for sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant