Skip to content

Conversation

yordis
Copy link
Contributor

@yordis yordis commented Apr 24, 2025

closes #408

@yordis
Copy link
Contributor Author

yordis commented May 5, 2025

It seems that full_name could be deterministic at compile time

syntax = "proto3";
package demo.v1;

import "google/protobuf/any.proto";

message Example {
  message NestedFirstLevel {
    message NestedSecondLevel {}

    NestedSecondLevel nested_second = 1;
  }

  enum NestedTypes {
    TYPE_UNSPECIFIED = 0;
    TYPE_ONE = 1;
    TYPE_TWO = 2;
  }

  NestedFirstLevel nested_first = 1;
  NestedTypes type = 2;
}

enum TopLevelEnum {
  TOP_LEVEL_UNSPECIFIED = 0;
  TOP_LEVEL_ONE = 1;
  TOP_LEVEL_TWO = 2;
}

message Integration {
  google.protobuf.Any data = 1;
}
package demo__test

import (
	"fmt"
	"github.com/stretchr/testify/assert"
	"google.golang.org/protobuf/reflect/protoreflect"
	"testing"
	demov1 "demo/gen/pb/demo/v1"
)

func TestName(t *testing.T) {
	nestedFirstNestedSecond := &demov1.Example_NestedFirstLevel_NestedSecondLevel{}
	nestedFirst := &demov1.Example_NestedFirstLevel{NestedSecond: nestedFirstNestedSecond}
	example := demov1.Example{NestedFirst: nestedFirst}

	exampleName := fullName(&example)
	fmt.Printf("%v", exampleName)

	nestedFirstName := fullName(example.GetNestedFirst())
	nestedFirstNameTop := fullName(nestedFirst)
	fmt.Printf("%v  --- %v", nestedFirstName, nestedFirstNameTop)
	assert.Equal(t, nestedFirstName, nestedFirstNameTop)

	nestedFirstNestedSecondName := fullName(example.GetNestedFirst().GetNestedSecond())
	nestedFirstNestedSecondNameTop := fullName(nestedFirstNestedSecond)
	fmt.Printf("%v --- %v", nestedFirstNestedSecondName, nestedFirstNestedSecondNameTop)
	assert.Equal(t, nestedFirstNestedSecondName, nestedFirstNestedSecondNameTop)
}

func fullName(msg protoreflect.ProtoMessage) protoreflect.FullName {
	return msg.ProtoReflect().Descriptor().FullName()
}

@yordis
Copy link
Contributor Author

yordis commented May 5, 2025

It seems that Golang does not allow me pass enum values to anypkg, so I think that such full_name isn't in there for the enum values since it always exists inside a message as a type

Screenshot 2025-05-05 at 5 12 40 PM

@yordis yordis force-pushed the fixes-408 branch 6 times, most recently from c828171 to 9c3504b Compare May 5, 2025 21:58
@yordis
Copy link
Contributor Author

yordis commented May 5, 2025

@yordis yordis requested a review from v0idpwn May 31, 2025 02:11
@yordis yordis marked this pull request as ready for review May 31, 2025 02:11
@yordis
Copy link
Contributor Author

yordis commented May 31, 2025

@whatyouhide @v0idpwn I think it is ready to code review, at least adding the fallback to follow up on Any type

@yordis yordis force-pushed the fixes-408 branch 2 times, most recently from 5acfd35 to ffe23ba Compare May 31, 2025 02:13
@yordis
Copy link
Contributor Author

yordis commented May 31, 2025

As far as I can tell package is technically required, a lot of test cases where such information is missing, I wonder if that should be fixed

@yordis
Copy link
Contributor Author

yordis commented Jun 2, 2025

** (RuntimeError) reading from :stdio failed: {:error, {:no_translation, :unicode, :latin1}}

What in the world is that 🤔

@whatyouhide
Copy link
Collaborator

Mh yeah, I have very vague memories of this but no notes on it, sorry 😭 I don't really have cycles to look into this now :(

@yordis yordis force-pushed the fixes-408 branch 2 times, most recently from 8898148 to bf9c878 Compare September 3, 2025 19:22
@sindrip
Copy link
Contributor

sindrip commented Sep 27, 2025

Hi @yordis I'm familiar with this error, it is something that came in OTP 26, there is good context here with a fix and a link to the issue in OTP: https://elixirforum.com/t/apparent-regression-reading-binary-data-from-stdio-in-erlang-26/57111/3

If you are simply looking for a way to get CI to pass, this is one way to do it: sindrip@f99091d

    env:
      MIX_ENV: test
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      # Set locale to handle encoding issues in newer Elixir versions
      LC_ALL: C.UTF-8
      LANG: C.UTF-8
      ERL_AFLAGS: "-kernel standard_io_encoding latin1"

And then you would have to re-generate some files and CI will pass.

Now I have another suggestion, and maybe this is better suited for @whatyouhide or @v0idpwn but there seems to be a way to pass this to the generated escript, as I do need to pass these kernel encoding flags to a lot of generation scripts that I use at work which is tedious.

And that could be done maybe like this: sindrip@7c4f3f1

  defp escript do
    [
      main_module: Protobuf.Protoc.CLI,
      name: "protoc-gen-elixir",
      emu_args: emu_args()
    ]
  end

  defp emu_args() do
    case :erlang.system_info(:otp_release) do
      v when v in [~c"26", ~c"27"] -> "-kernel standard_io_encoding latin1"
      _ -> ""
    end
  end

But it is not thoroughly tested (although it also works in CI.)

@yordis
Copy link
Contributor Author

yordis commented Sep 27, 2025

@sindrip my hero 🦸‍♂️

@yordis yordis force-pushed the fixes-408 branch 2 times, most recently from 4b3dd16 to c773b23 Compare September 27, 2025 15:17
@yordis
Copy link
Contributor Author

yordis commented Sep 27, 2025

@v0idpwn @whatyouhide IT IS PASSING!!!!!!!!!! I am so happy right now

@georgecoss
Copy link

thank you for helping to work toward supporting grpc error details in elixir!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add full_name/0 to message module

5 participants