Skip to content

Add better error messages when Outfit construction fails.#110

Open
Kasekopf wants to merge 9 commits intoloathers:mainfrom
Kasekopf:equipv
Open

Add better error messages when Outfit construction fails.#110
Kasekopf wants to merge 9 commits intoloathers:mainfrom
Kasekopf:equipv

Conversation

@Kasekopf
Copy link
Member

@Kasekopf Kasekopf commented Jul 31, 2023

This PR adds outfit.equipVerbose which either succeeds in equipping a thing or returns a string error message. This allows for forceEquip which throws the message as an error.

Internally, all the private subfunctions to modify the outfit have been changed to also return a string error message on failure.

src/outfit.ts Outdated
};
}

const SUCCESS: EquipResult = { success: true };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This being mutable and reused leads to an extremely, extremely funny failure case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In particular, because the SUCCESS object itself gets returned, it can cause a problem.

src/outfit.ts Outdated
function mergeResults(results: EquipResult[]) {
const failures = results.filter((r) => !r.success) as { reason: string }[];
if (failures.length === 0) return SUCCESS;
return fail(failures.map((r) => r.reason).join(" "));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how I feel about a space as the delimiter

@spaghetti-squash
Copy link
Contributor

spaghetti-squash commented May 31, 2024

I recognize I'm commenting on a PR that's been open for a year but it would be nice to be able to toggle verbosity globally rather than based on which methods you call, ideally using libram's log levels or something similar.

Would tie in nicely with #111

@MrFizzyBubbs
Copy link
Contributor

This would be a very nice addition

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

Successfully merging this pull request may close these issues.

3 participants