[Gambas-user] tracking down toolkit erors
Brian G
brian at westwoodsvcs.com
Tue Aug 10 07:49:32 CEST 2021
Bruce,
If you make the following change your errors will go to the console
and all underlying C code errors will go to the pipe. No need for filters in the
File_read function. probably a good idea to log them in case anything really
does go wrong.
If you don't want to capture those errors at all then just make writer open as "/dev/null"
skip the whole open for read.
"Failure is the key to success;
each mistake teaches us something" .. Morihei Ueshiba
Brian G
----- On Aug 9, 2021, at 7:41 AM, Bruce Steers <bsteers4 at gmail.com> wrote:
> Many Thanks BrianG. With this and your other help I now have this routine....
> ' Gambas class file
> Extern dup2(OldFD As Integer, newfd As Integer) In "libc:6"
> Private Writer As File
> Private Reader As File
> Private restore As File
> Public Sub _new()
> Writer = Open Pipe "/tmp/testpipeout" For Write
> restore = File.Err
> dup2(Writer.handle, 2)
> Reader = Open Pipe "/tmp/testpipeout" For Read Watch
> End
Public Sub _new()
Writer = Open Pipe "/tmp/testpipeout" For Write
' get the error destination to a known handle
restore = Open "/dev/null" For Write ' open any old file to get a handle
dup2(2, restore.handle) ' Make that handle equal std error
Error To restore ' point gambas's error output to the original term
dup2(Writer.handle, 2)
Reader = Open Pipe "/tmp/testpipeout" For Read Watch
End
Alternatively if not wanting to capture the other libc errors then just:
Public Sub _new()
Writer = Open Pipe "/dev/null" For Write
' get the error destination to a known handle
restore = Open "/dev/null" For Write ' open any old file to get handle
dup2(2, restore.handle) ' Make that handle equal std error
Error To restore ' point gambas's error output to the original term
dup2(Writer.handle, 2) ' All other outputs to null don't need file_read at all
End
> Public Sub File_read()
> Dim buffer As String
> buffer = Read #Last, -Lof(Last)
> For Each sLine As String In Split(buffer, "\n")
> If Not sLine Then Continue
> If sLine Like "(" & Application.Name & ":*): G*k-*" Then Continue
> Print sLine
> Next
> End
Public Sub File_read()
Dim buffer As String
buffer = Read #Last, -Lof(Last)
'' write to some logfile here maybe
End
> Public Sub Form_Close()
> If Writer Then Writer.Close()
> If Reader Then Reader.Close()
> dup2(restore.handle, 2)
> End
> Public Sub Button1_Click()
> Print "Print Something"
> Debug "Debug Something"
Error "something"
> End
> I had to check each line of the buffer individually and used Like to
> pattern-match the Gtk- Gdk- messages
> So with that code my own Debug and Error messages still output (albeit to stdout
> but that's fine) just the gtk/gdk messages are gone :)
> Thanks again Brian , much respect :)
> BruceS
> On Sun, 8 Aug 2021 at 03:34, Brian G < [ mailto:brian at westwoodsvcs.com |
> brian at westwoodsvcs.com ] > wrote:
>> Bruce replace your _new with this code
>> Extern dup2(OldFD As Integer, newfd As Integer) In "libc:6"
>> Static Dummy As File
>> Static Public Sub _init()
>> dummy = Open "/dev/null" For Write
>> dup2(dummy.Handle, 1)
>> dup2(dummy.handle, 2)
>> End
>> Should give you what you want without all the fiddle
>> "Failure is the key to success;
>> each mistake teaches us something" .. Morihei Ueshiba
>> Brian G
>> ----- On Aug 7, 2021, at 12:39 PM, Bruce Steers < [ mailto:bsteers4 at gmail.com |
>> bsteers4 at gmail.com ] > wrote:
>>> On Thu, 5 Aug 2021 at 20:34, Bruce Steers < [ mailto:bsteers4 at gmail.com |
>>> bsteers4 at gmail.com ] > wrote:
>>>> On Wed, 4 Aug 2021 at 00:53, < [ mailto:jose.rodriguez at cenpalab.cu |
>>>> jose.rodriguez at cenpalab.cu ] > wrote:
>>>>> August 3, 2021 2:29 PM, "Bruce Steers" < [
>>>>> mailto:bsteers4 at gmail.com?to=%22Bruce%20Steers%22%20%3Cbsteers4 at gmail.com%3E |
>>>>> bsteers4 at gmail.com ] > wrote:
>>>>>> I have this program i'm developing that was starting and stopping cleanly then i
>>>>>> recently added some controls and did various other things and now it says this
>>>>>> when it starts...
>>>>>> (Desktop-ish:12906): Gtk-WARNING **: 16:29:25.336: Theme parsing error:
>>>>>> <data>:1:15: Expected a valid selectorIs there a way to track down what's
>>>>>> causing it?
>>>>>> thanks
>>>>>> BruceS
>>>>> GTK has always output loads of different errors with many programs (not gambas
>>>>> ones, I mean), when run in a terminal. People say it depends on the current
>>>>> theme and whatnot...
>>>> Indeed, Pluma was always my texteditor of choice and that used to pump out loads
>>>> of warnings.
>>>> (but now of course i use my own editor i wrote with gambas that has all those
>>>> cool Texteditor features ;) )
>>>> Would be great to be able to catch the warnings though.
>>>> Either a way to track what exactly is causing them or just suppress the
>>>> messages.
>>>> BruceS
>>> so best answer i have so far is this "hack"...
>>> Uses gb.args
>>> if the arg -q or --quiet is given then before the app loads it launches itself
>>> with any and all args plus "2>/dev/null" to redirect the error output and an
>>> additional arg -s.
>>> when the 2nd run instance quits the 1st one that launched the second one also
>>> quits before it's even done anything.
>>> Public Sub _new()
>>> Args.Begin()
>>> Dim bQuiet As Boolean = Args.Has("q", "quiet", "supress gtk error messages")
>>> If bQuiet Then bQuiet = (Args.Has("s", "supressed", "supressed gtk error
>>> warnings") == False)
>>> Args.End()
>>> If bQuiet And File.In.IsTerm Then ' if we are not run from a terminal then no
>>> need for any of this
>>> Dim sRestOfargs As String[] = Args.All.Copy()
>>> ' the next 2 lines just handle if being run from the IDE and make Arg[0] be
>>> executable name.
>>> If Not InStr(sRestOfargs[0], "/") Then sRestOfargs[0] = Application.Path &/
>>> Application.Name
>>> If File.Ext(sRestOfargs[0]) <> "gambas" Then sRestOfargs[0] &= ".gambas"
>>> sRestOfargs.Insert(["-s", "2>/dev/null"])
>>> Shell sRestOfargs.Join(" ")
>>> Me.Close
>>> Return
>>> Endif
>>> End
>>> Attached is a simple test app
>>> It's a form with a tiny little TextArea in it, so small it produces warnings on
>>> my system when i move the mouse around the window...
>>> (Test:79673): Gdk-CRITICAL **: 20:26:58.775: gdk_window_is_visible: assertion
>>> 'GDK_IS_WINDOW (window)' failed
>>> Run with -q and all is quiet.
>>> ./Test.gambas -q
>>> Of course this method will suppress ANY error messages ,
>>> shell commands can be fixed by adding '>2&1'
>>> Shell "/run/mycommand 2>&1"
>>> that redirects error output to stdout and stdout is still showing
>>> Please somebody tell me there's a better way...
>>> BruceS
>>> ----[ [ http://gambaswiki.org/wiki/doc/netiquette |
>>> http://gambaswiki.org/wiki/doc/netiquette ] ]----
>> ----[ [ http://gambaswiki.org/wiki/doc/netiquette |
>> http://gambaswiki.org/wiki/doc/netiquette ] ]----
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210809/ca0558c5/attachment-0001.htm>
More information about the User
mailing list