Skip to content
⌘ NSIS Forum Archive

Compiler error or warning if define is missing

8 posts

dasung#edited

Compiler error or warning if define is missing

Hi,

I need to set error levels for NSIS script itself.
I have followed this link but I am not sure this is the correct reference for my purpose.



I want to show an error/warning in cmd when I execute NSIS script.

E.g:
If any unset variable used in the script.
By default NSIS script just ignoring those and continue execution. 😕

VIAddVersionKey "FileDescription" "My Max ${MAX_VERSION} Installer"

For above script, I need to see a warning/error for undefined variable MAX_VERSION.

Is there anyway to set error level before executing the script?

Thank you.
Anders#
You keep saying variable but ${xyz} is a define!

If you want to check that it exists when compiling just do this:
!ifndef MAX_VERSION
!error "MAX_VERSION not set!"
!endif 
dasung#
Originally Posted by Anders View Post
You keep saying variable but ${xyz} is a define!
!ifndef MAX_VERSION
!error "MAX_VERSION not set!"
!endif 
variable is not define.
Above suggestion is okay.

But I have lots of variables in nsis script which may increase the clutter for "!ifndef" checking.
What I am thinking to set an error level at the beginning of the script.

:COMPILE
%MAKENSIS_BIN%  /DX64  installer.nsi
goto END
:END
pause 
Can i set an error level this point as to show warning while executing the script?


Also, I tried "/WS" flag which is not working at all.
Anders#
Use !warning for warnings. (Doh)

Originally Posted by dasung View Post
Can i set an error level this point as to show warning while executing the script?

You keep talking about the errorlevel but the thing you are linking to is the exit codes for the generated installer, not the compiler!

The batch code you posted makes no sense, where are you even checking the exit code? Go read about "if errorlevel 1" or "&&" and then try again.


Originally Posted by dasung View Post


Also, I tried "/WS" flag which is not working at all.
http://nsis.sourceforge.net/Docs/Chapter3.html
There is no such thing as /WS! You probably mean /WX and that only works in NSIS 3...
dasung#
Originally Posted by Anders View Post
Use !warning for warnings. (Doh)
There is no such thing as /WS! You probably mean /WX and that only works in NSIS 3...
Yes.
I was referred "/WX treats warnings as errors" in compiler options.

couldn't understand even WX flag is not giving any warning / error for undefined variables. Do i miss something here?

As I understood so far, error level was not the solution for my problem.

That is for showing error levels, return by other applications (*.exe) to the nsis script.
Anders#
A missing define does not cause a warning. A missing variable will.

VIAddVersionKey "FileDescription" "My Max ${doesnotexist} Installer" ; No warning
Section
StrCpy $0 $doesnotexist
SectionEnd
!warning "NSIS ${NSIS_VERSION} (${NSIS_PACKEDVERSION})"
!error STOP 
makensis.exe test.nsi
...
warning: unknown variable/constant "doesnotexist" detected, ignoring (test.nsi:747)
warning: !warning: NSIS v3.0.6 (0x03000061) (test.nsi:749)
!error: STOP 
makensis.exe /WX test.nsi
...
warning: unknown variable/constant "doesnotexist" detected, ignoring (test.nsi:747)
Error: warning treated as error 
dasung#
Originally Posted by Anders View Post
VIAddVersionKey "FileDescription" "My Max ${doesnotexist} Installer" ; No warning
Section
StrCpy $0 $doesnotexist
SectionEnd
!warning "NSIS ${NSIS_VERSION} (${NSIS_PACKEDVERSION})"
!error STOP 
This is working.
btw sill i can't use "VIAddVersionKey" inside a section.
All warning are given inside a section only? If so, how do i use "VIAddVersionKey" inside a section.
Anders#
Originally Posted by dasung View Post
This is working.
btw sill i can't use "VIAddVersionKey" inside a section.
All warning are given inside a section only? If so, how do i use "VIAddVersionKey" inside a section.
VIAddVersionKey is a attribute, not code to be executed and therefore it cannot be used in a section/function.