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

bug when using format.js with a single file #243

Closed
plamen-ppv opened this issue Mar 21, 2023 · 5 comments · Fixed by #245
Closed

bug when using format.js with a single file #243

plamen-ppv opened this issue Mar 21, 2023 · 5 comments · Fixed by #245
Assignees
Labels
bug Something isn't working
Milestone

Comments

@plamen-ppv
Copy link

Hi Philip!

Thanks for providing such a nice tool for formatting SQL from within SQLcl!
I've been using it n SQLcl 22.4 and it works fine.

... but I found one bug:
if you run it with a single file instead of directory, i.e.
tvdformat c:\temp\x.sql xml=....
then the call from getFiles() to isRelevantFile() fails with Java type cast error - line 60 in format.js.
It's a very easy fix:
from
if (isRelevantFile(rootPath, extensions, ignoreMatcher)) {
to
if (isRelevantFile(javaPaths.get(rootPath), extensions, ignoreMatcher)) {

Best regards,
Plamen

@PhilippSalvisberg
Copy link
Collaborator

Hi @plamen-ppv

Thanks for reporting this. I was not able to reproduce it on my MacBook.

SQLcl: Release 22.4 Production on Tue Mar 21 12:24:16 2023

Copyright (c) 1982, 2023, Oracle.  All rights reserved.

SQL> tvdformat /tmp/test.sql

Formatting file 1 of 1: /tmp/test.sql... done.
SQL> 

Maybe it is platform specific. I have to test it on Windows.

@PhilippSalvisberg PhilippSalvisberg self-assigned this Mar 21, 2023
@PhilippSalvisberg
Copy link
Collaborator

I tried tvdformat.jar on Windows 11 with Java17. Works as well:

java -jar tvdformat.jar c:\temp\test.sql xml=embedded arbori=default

Formatting file 1 of 1: c:\temp\test.sql... done.

@PhilippSalvisberg
Copy link
Collaborator

I tested it on Windows 10 with Java 11 and the latest SQLcl:

SQL> tvdformat c:\temp\test.sql

Formatting file 1 of 1: c:\temp\test.sql... done.
SQL> script format.js c:\temp\test.sql

Formatting file 1 of 1: c:\temp\test.sql... done.
SQL>

@plamen-ppv I cannot reproduce the problem. Could you please provide some details about your environment to make it reproducible?

@plamen-ppv
Copy link
Author

Hi Philipp,

You are right - it works when you just have one argument. I only used it together with ignore:

SQL> tvdformat C:/temp/test.sql ignore=C:/temp/ignore_format.txt
2023-03-21 14:19:43.536 SEVERE oracle.dbtools.raptor.newscriptrunner.ScriptExecutor run java.base/java.lang.Class.cast(Class.java:3605)
java.lang.ClassCastException: Cannot cast java.lang.String to java.nio.file.Path
        at java.base/java.lang.Class.cast(Class.java:3605)
        at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$127$3280AAA$\^eval\_.isRelevantFile(<eval>:77)
        at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$130$2444AAA$\^eval\_.getFiles(<eval>:61)
        at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$131$28965A$\^eval\_.run(<eval>:685)
        at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$60$31631AAA$\^eval\_.registerTvdFormat#handleEvent(<eval>:722)
        at jdk.nashorn.javaadapters.oracle_dbtools_raptor_newscriptrunner_CommandListener.handleEvent(Unknown Source)
        at oracle.dbtools.raptor.newscriptrunner.CommandRegistry.fireListeners(CommandRegistry.java:439)
        at oracle.dbtools.raptor.newscriptrunner.ScriptRunner.run(ScriptRunner.java:237)
        at oracle.dbtools.raptor.newscriptrunner.ScriptExecutor.run(ScriptExecutor.java:356)
        at oracle.dbtools.raptor.newscriptrunner.ScriptExecutor.run(ScriptExecutor.java:239)
        at oracle.dbtools.raptor.scriptrunner.cmdline.SqlCli.processLine(SqlCli.java:1150)
        at oracle.dbtools.raptor.scriptrunner.cmdline.SqlCli.runSqlcl(SqlCli.java:1331)
        at oracle.dbtools.raptor.scriptrunner.cmdline.SqlCli.main(SqlCli.java:339)

The offending line is 76 where "file" as string is passed to ignoreMatcher.matches(file)

Cheers,
Plamen

@PhilippSalvisberg
Copy link
Collaborator

Thanks @plamen-ppv . I can reproduce it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants