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

Wails V2.8.0 KnownStructs output should not be output to STD_ERROR. #3331

Open
bwenquan opened this issue Mar 21, 2024 · 1 comment
Open
Labels
Bug Something isn't working Workaround Available

Comments

@bwenquan
Copy link

Description

When I redirect error output to file on Windows, I found a lot of output from wails.

	if runtime.GOOS == "windows" {
		file, err := os.OpenFile("log/panic.log", os.O_CREATE|os.O_APPEND, 0666)
		globalFile = file
		if err != nil {
			return err
		}
		kernel32 := syscall.NewLazyDLL("kernel32.dll")
		setStdHandle := kernel32.NewProc("SetStdHandle")
		sh := syscall.STD_ERROR_HANDLE
		v, _, err := setStdHandle.Call(uintptr(sh), uintptr(globalFile.Fd()))
		if v == 0 {
			return err
		}
	}

image

I checked the wails source code and found output here is println:
image

But println wtrites the result to standard error
image

To Reproduce

file internal\typescriptify\typescriptify.go line 659, 660

...
			if field.Type.Name() != "" {
				typeScriptChunk, err := t.convertType(depth+1, field.Type, customCode)
				if err != nil {
					return "", err
				}
				if typeScriptChunk != "" {
					result = typeScriptChunk + "\n" + result
				}
			}

			isKnownType := t.KnownStructs.Contains(getStructFQN(field.Type.String()))
->			println("KnownStructs:", t.KnownStructs.Join("\t"))
->			println(getStructFQN(field.Type.String()))
			builder.AddStructField(jsonFieldName, field, !isKnownType)
		} else if field.Type.Kind() == reflect.Map {
			t.logf(depth, "- map field %s.%s", typeOf.Name(), field.Name)
			// Also convert map key types if needed
			var keyTypeToConvert reflect.Type
			switch field.Type.Key().Kind() {
			case reflect.Struct:
				keyTypeToConvert = field.Type.Key()
			case reflect.Ptr:
				keyTypeToConvert = field.Type.Key().Elem()
			}
...

Expected behaviour

Write to standard output

Screenshots

No response

Attempted Fixes

This shuould be write to std output. such as fmt.println

System Details

# Wails
Version | v2.8.0

Additional context

No response

@bwenquan bwenquan added the Bug Something isn't working label Mar 21, 2024
@stffabi
Copy link
Collaborator

stffabi commented Mar 21, 2024

Thanks for using Wails and reporting this.

I'm not sure we are going to change this for v2 anymore, because in v3 we use static analysis to generate the bindings.

Nevertheless you can use the build tag bindings to detect if the app is being built for binding generation or not. So if the bindings tag is used, you can conditionally skip the setup of the panic.log error handler and you should be fine.

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

No branches or pull requests

2 participants