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

[Fix 72] generator config is not case-sensitive consistent #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

uroboro
Copy link
Member

@uroboro uroboro commented Aug 29, 2022

What does this implement/fix? Explain your changes.

Perl's can_load is case-insensitive which means that the system can find case variations of generator names but Thunk later cannot properly load the module.

For now, it detects the typo on the generator name but only warns the user instead of assuming which one they intended, to prevent allowing variations of the names to be used in source code.

Does this close any currently open issues?

#72

Copy link
Member

@L1ghtmann L1ghtmann left a comment

Choose a reason for hiding this comment

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

I can't recall why we didn't merge this in earlier, but looking at it again now I've noticed two things:

  1. I can't seem to replicate the error provided in %config(generator=Internal) does not work but using internal does #72, but do get an error message:
Could not find or check module 'Logos::Generator::Internal::Generator' [THIS MAY BE A PROBLEM!] at /home/lightmann/logos/bin/lib/Logos/Generator.pm line 45.
/home/lightmann/gen/Tweak.x: error: I can't find the 'Internal' Generator!
  1. It seems like the additional check may be backwards: can_load appears to be case-sensitive, so we would want to pop the generator suggestion if the load attempt comes back empty

bin/lib/Logos/Generator.pm Outdated Show resolved Hide resolved
bin/lib/Logos/Generator.pm Outdated Show resolved Hide resolved
@uroboro
Copy link
Member Author

uroboro commented Dec 28, 2023

As Ethan explained in the issue thread, you can get the errors with just the %config line as the source code:

➤ for f in *; bat --pager none $f; logos.pl $f; end
───────┬───────────────────────────────────────────────────────────────────────────────────────
       │ File: generator.x
───────┼───────────────────────────────────────────────────────────────────────────────────────
   1   │ %config(generator=internal)
   2   │ 
───────┴───────────────────────────────────────────────────────────────────────────────────────
#line 1 "generator.x"


───────┬───────────────────────────────────────────────────────────────────────────────────────
       │ File: generator_bad_case.x
───────┼───────────────────────────────────────────────────────────────────────────────────────
   1   │ %config(generator=Internal)
   2   │ 
───────┴───────────────────────────────────────────────────────────────────────────────────────
Goto undefined subroutine &main:: at /Users/uroboro/theos/vendor/logos/bin/lib/Logos/Generator/Thunk.pm line 33.
───────┬───────────────────────────────────────────────────────────────────────────────────────
       │ File: generator_inexistent.x
───────┼───────────────────────────────────────────────────────────────────────────────────────
   1   │ %config(generator=Internals)
   2   │ 
───────┴───────────────────────────────────────────────────────────────────────────────────────
Could not find or check module 'Logos::Generator::Internals::Generator' [THIS MAY BE A PROBLEM!] at /Users/uroboro/theos/vendor/logos/bin/lib/Logos/Generator.pm line 45.
generator_inexistent.x: error: I can't find the 'Internals' Generator!

It is possible that I'm seeing this issue with a case insensitive filesystem because I'm using MacOS (with changes in this PR):

➤ for f in *; bat --pager none $f; logos.pl $f; end
───────┬───────────────────────────────────────────────────────────────────────────────────────
       │ File: generator.x
───────┼───────────────────────────────────────────────────────────────────────────────────────
   1   │ %config(generator=internal)
   2   │ 
───────┴───────────────────────────────────────────────────────────────────────────────────────
#line 1 "generator.x"


───────┬───────────────────────────────────────────────────────────────────────────────────────
       │ File: generator_bad_case.x
───────┼───────────────────────────────────────────────────────────────────────────────────────
   1   │ %config(generator=Internal)
   2   │ 
───────┴───────────────────────────────────────────────────────────────────────────────────────
generator_bad_case.x: error: I can't find the 'Internal' Generator, did you mean 'internal'?
───────┬───────────────────────────────────────────────────────────────────────────────────────
       │ File: generator_inexistent.x
───────┼───────────────────────────────────────────────────────────────────────────────────────
   1   │ %config(generator=Internals)
   2   │ 
───────┴───────────────────────────────────────────────────────────────────────────────────────
Could not find or check module 'Logos::Generator::Internals::Generator' [THIS MAY BE A PROBLEM!] at /Users/uroboro/theos/vendor/logos/bin/lib/Logos/Generator.pm line 45.
generator_inexistent.x: error: I can't find the 'Internals' Generator!

Regarding the check logic, can_load fails if it cannot find the module (according to case sensitive rules of the file system). On a case sensitive system, it won't find an 'Internal' module because it's called 'internal', but on a case insensitive it will.

Somewhere in between this and Thunk, the loading of the module does not happen in case insensitive systems and logos shows that "Goto undefined subroutine &main:: at" message. I'll simplify the logic to just make my additions as just an extra piece of code (leave lines 43-45 as they were originally).

BTW, the $Module::Load::Conditional::VERBOSE = 1; at the top might be unnecessary since we always show "....x: error: I can't find the 'Internals' Generator!" message.

Perl's `can_load` is case-insensitive which means that the system can find case variations of generator names but `Thunk` later cannot properly load the module.

For now, it detects the typo on the generator name but only warns the user instead of assuming which one they intended, to prevent allowing variations of the names to be used in source code.
Copy link
Member

@L1ghtmann L1ghtmann left a comment

Choose a reason for hiding this comment

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

It is possible that I'm seeing this issue with a case insensitive filesystem because I'm using MacOS (with changes in this PR):

Ah, that would explain it. I am unable to repro the goto error on Linux as it is case-sensitive.

BTW, the $Module::Load::Conditional::VERBOSE = 1; at the top might be unnecessary since we always show "....x: error: I can't find the 'Internals' Generator!" message.

I'm not familiar enough with Perl ... does VERBOSE apply everywhere? It seems the only mention of it in the codebase is here.


If we're interested in adjusting the logic to also attempt to advise on generator case for case-sensitive systems, it seems that minimal changes would be required (see comment below). Result with the proposed changes:

%config(generator=internal)
#line 1 "generator.x"

%config(generator=Internal)
generator.x: error: I can't find the 'Internal' Generator, did you mean 'internal'?
%config(generator=Internals)
Could not find or check module 'Logos::Generator::Internals::Generator' [THIS MAY BE A PROBLEM!] at /home/lightmann/logos/bin/lib/Logos/Generator.pm line 59.
generator.x: error: I can't find the 'Internals' Generator!

if ($generatorDirectoryExists != 1) {
my %generatorNames = map {lc($_) => $_} @availableGenerators;
my $possibleGeneratorName = $generatorNames{lc($generatorName)};
::fileError(-1, "I can't find the '$generatorName' Generator, did you mean '$possibleGeneratorName'?");
Copy link
Member

Choose a reason for hiding this comment

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

For case-sensitive OS support:

  • Move this new code block above the existing $GeneratorPackage block and fall back to the existing fileError if we have no name suggestion.
Suggested change
::fileError(-1, "I can't find the '$generatorName' Generator, did you mean '$possibleGeneratorName'?");
if ($possibleGeneratorName) {
::fileError(-1, "I can't find the '$generatorName' Generator, did you mean '$possibleGeneratorName'?");
}

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.

None yet

2 participants