# Show error in a messagebox during submit.yml.erb exec

**URL:** <https://discourse.openondemand.org/t/show-error-in-a-messagebox-during-submit-yml-erb-exec/432>\
**Category:** Get Help\
**Created:** [July 16, 2019, 5:37am UTC](https://discourse.openondemand.org/t/show-error-in-a-messagebox-during-submit-yml-erb-exec/432 "2019-07-16T05:37:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jms27000](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jms27000/32/147_2.png) [@jms27000](https://discourse.openondemand.org/u/jms27000)\
**Post date:** [July 16, 2019, 5:37am UTC](https://discourse.openondemand.org/t/show-error-in-a-messagebox-during-submit-yml-erb-exec/432/1 "2019-07-16T05:37:55Z")

</div>

Hello,

My purpose is to share a VNC session per user, with no time limit, to allow differents graphical jobs to use it. one user = one display = several graphical jobs. simple.

so i would like to verifiy some prerequites before submit to slurm :

- is there a graphical VNC session running ?
- what is the DISPLAY variable assigned to this VNC session

in case of error, i would like to open a messagebox to tell the user to open a VNC session first.

as this is a recurrent task, how to put this code into an external function script, working as a library ?

for the moment, i have realized this topic into the script.sh.erb by copying the same section of verifications. not very nice, not comprehensive for the user, because the error is logged into the output.log file after submission.

i’m working on ood 1.6.7. some ideas, please ?

note : the top would be to launch automaticaly the VNC session if missing.

thanks a lot

jean-marie

---

<div class="post-metadata">

**Author:** ![efranz](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/efranz/32/27_2.png) [@efranz](https://discourse.openondemand.org/u/efranz)\
**Post date:** [July 16, 2019, 5:37pm UTC](https://discourse.openondemand.org/t/show-error-in-a-messagebox-during-submit-yml-erb-exec/432/2 "2019-07-16T17:37:10Z")

</div>

In the submit.yml.erb you can raise an exception with a message, and the message will appear in an error message to the user and no (this was [fixed in the 1.6 release](https://github.com/OSC/ood-dashboard/issues/451) as before that files would be copied unnecessarily when an error occurred).

For example, in erb tags I do `raise "This is an error message"` and when I submit the form I get this error:

 ![07%20PM](https://us1.discourse-cdn.com/flex015/uploads/osc/original/1X/ba3fe9e26df11fae1225977eea897b9c6acb15c3.png)

- Note I do realize after seeing this that the footnote in the error message is no longer helpful because files are not copied if the error takes place.

As for having code in a function you can call from your erb in interactive apps, one way is to add this to the Rails initializer for the Dashboard app. See [https://listsprd.osu.edu/pipermail/ood-users/2018-November/000297.html](https://listsprd.osu.edu/pipermail/ood-users/2018-November/000297.html) for an example of how to do this. It is important to create a module with your institution name or something that would never conflict with another module.

The idea is the initizializer defines a module and a class with the methods you want (and can even memoize return values using instance variables as a simple cache) and then you can use these in the interactive app erb files.

---

<div class="post-metadata">

**Author:** ![jms27000](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jms27000/32/147_2.png) [@jms27000](https://discourse.openondemand.org/u/jms27000)\
**Post date:** [July 21, 2019, 7:19am UTC](https://discourse.openondemand.org/t/show-error-in-a-messagebox-during-submit-yml-erb-exec/432/3 "2019-07-21T07:19:16Z")

</div>

Hi,  
To follow your proposal, my colleague and I have tried to implement this process on a PARAVIEW example :

if no vnc motif session is launched by the user, the PARAVIEW template has to stop on a raise message before starting the slurm job.

in fact, it goes on and it’s failed into the job, of course.

why. because the “vnc\_display” stays with the previous good value.

here is a trap on the different files done at the same times :

Every 10,0s: cat /tmp/disp\_jms.log /tmp/form.log /t… Sun Jul 21 09:18:29 2019

display : date Sun Jul 21 09:18:20 CEST 2019  
display : user jms  
display : myFile /home/jms/.vnc/motif.log  
display : ligne  
display : display none

form : date Sun Jul 21 09:18:20 CEST 2019  
form : none

submit : date Sun Jul 21 09:17:07 CEST 2019  
submit : DISPLAY=nodeSu-001:1

QUESTION : what’s going wrong ?

here are the files implemented :

cat /etc/ood/config/apps/dashboard/initializers/display.rb

def qdisplay  
@DISPLAY = “none”  
@myFile = ENV[‘HOME’] + “/.vnc/motif.log”  
@myLogFile = “/tmp/disp\_”+ENV[‘USER’]+".log"  
system ("rm -f "+@myLogFile)  
system ("touch "+@myLogFile)  
@date = %x[date]  
@ligne = %x[squeue -u USER -n MOTIF|tail -1f | grep MOTIF] if ?.exitstatus == 0 then  
aFile = File.open(@myFile, “r”)  
if aFile then

# @DISPLAY = aFile.sysread(80)

```
  		@DISPLAY = aFile.read()
	end	 
   	aFile.close
end

aFile = File.open(@myLogFile, "w")
aFile.puts("display : date "+@date)
aFile.puts("display : user "+ENV['USER'])
aFile.puts("display : myFile "+@myFile)
aFile.puts("display : ligne "+@ligne)
aFile.puts("display : display "+@DISPLAY)
aFile.puts()
aFile.close

return @DISPLAY

```

end

cat /var/www/ood/apps/sys/VIEW/form.yml.erb

## \<%- projects = OodAppkit.clusters[:verhpc].custom\_config[:projects] vnc\_disp = qdisplay @date = %x[date] aFile = File.new("/tmp/form.log", “w”) aFile.puts("form : date "+@date) aFile.puts("form : "+vnc\_disp) aFile.puts() aFile.close -%\>

cluster: “verhpc”  
form:

- version
- work\_dir
- project
- num\_cores
- memory\_by\_core
- vnc\_disp
- bc\_vnc\_resolution  
attributes:  
version:  
widget: select  
label: “Paraview version”  
help: “This defines the version of PARAVIEW you want to load.”  
options:
  - [“5.3.0”, “software/paraview/5.3.0”]  
work\_dir:  
widget: “text\_field”  
label: “Working Directory”  
help: “Type the name of the directory you want to working in”  
project:  
widget: select  
label: “Project”  
help: “You can leave this blank if **not** in multiple projects.”  
options:  
\<%- projects.each do |p| -%\>
  - [“\<%= p %\>”, “\<%= p %\>”]  
\<%- end -%\>

num\_cores:  
widget: “number\_field”  
label: “Number of cores”  
help: |  
Number of cores on node type (4 GB per core unless requesting whole  
node). Leave blank if requesting full node.  
min: 0 # This is treated as requesting the max allowable  
max: 1 # This will be updated by form.js  
step: 1  
id: num\_cores  
memory\_by\_core:  
widget: “number\_field”  
label: “Memory by core”  
help: |  
Number of memory by core. Leave blank if requesting anything.  
min: 0 # This is treated as requesting the max allowable  
max: 2 # This will be updated by form.js  
step: 1  
id: memory\_by\_core

vnc\_disp:  
widget: “hidden\_field”

# widget: “text\_field”

```
value: <%= vnc_disp %>
id: vnc_disp

```

bc\_vnc\_resolution:  
required: true

cat /var/www/ood/apps/sys/VIEW/submit.yml.erb

\<%-  
nb\_cores = num\_cores.blank? ? 1 : num\_cores  
memory = memory\_by\_core.blank? ? 1 : memory\_by\_core  
vnc\_display = vnc\_disp  
@date = %x[date]  
aFile = File.new("/tmp/submit.log", “w”)  
aFile.puts("submit : date "+@date)  
aFile.puts("submit : “+vnc\_display)  
aFile.puts()  
aFile.close  
if vnc\_display == “none” then  
raise " Error : the display is not defined, please launch a motif desktop first”  
end

## -%\>

batch\_connect:  
template: “basic”  
script:  
native: [“-JPARAVIEW” , “-N” , “\<%= nb\_cores %\>” , --mem-per-cpu=\<%= memory %\> , “-pinter”]

---

<div class="post-metadata">

**Author:** ![westburg.2](https://avatars.discourse-cdn.com/v4/letter/w/0ea827/32.png) [@westburg.2](https://discourse.openondemand.org/u/westburg.2)\
**Post date:** [May 26, 2022, 3:20pm UTC](https://discourse.openondemand.org/t/show-error-in-a-messagebox-during-submit-yml-erb-exec/432/4 "2022-05-26T15:20:10Z")

</div>


